我正在構建基於JPA的應用程序,使用mysql和ecliselink.I嘗試向我的數據庫中插入東西時出現了很奇怪的問題。我能夠將數據插入到單個表中,但是當涉及到一對一時,可能和反之亦然東西出錯。目前我有2個主要和1參考表(它擁有其他兩個表的外鍵)。這是奇怪的,因爲我沒有「序列」在我的數據庫表中當我嘗試插入數據到任何我的表,我得到這個異常:JPA/MySql問題
[EL Info]: 2012-03-15 17:52:28.64--ServerSession(18621340)--EclipseLink, version: Eclipse Persistence Services - 2.3.2.v20111125-r10461
[EL Info]: 2012-03-15 17:52:29.23--ServerSession(18621340)--file:/D:/git-eclipse/Martin/reference/build/classes/_reference login successful
[EL Warning]: 2012-03-15 17:52:29.389--ClientSession(31843177)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'eclipse1.sequence' doesn't exist
Error Code: 1146
Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
bind => [2 parameters bound]
Query: DataModifyQuery(name="SEQUENCE" sql="UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?")
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'eclipse1.sequence' doesn't exist
Error Code: 1146
Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
bind => [2 parameters bound]
Query: DataModifyQuery(name="SEQUENCE" sql="UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?")
[EL Info]: 2012-03-15 17:52:29.394--ServerSession(18621340)--file:/D:/git-eclipse/Martin/reference/build/classes/_reference logout successful
Exception in thread "main" java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManager.
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.verifyOpen(EntityManagerImpl.java:1665)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.close(EntityManagerImpl.java:1529)
at OneToManyRelation.main(OneToManyRelation.java:47)
我張貼一類,只是因爲別人是非常相似的
@Entity
@Table(name="category")
public class Category {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="CategoryID")
private int CategoryID;
/**
* @return the id
*/
public int getId() {
return CategoryID;
}
/**
* @param id the id to set
*/
public void setId(int CategoryID) {
this.CategoryID = CategoryID;
}
@Column(name="category", nullable=false, length=50, insertable=true)
private String category;
/**
* @return the category
*/
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
@OneToMany(cascade=CascadeType.ALL)
@JoinTable(name = "templateemail", joinColumns = {
@JoinColumn(name="categoryId", unique = true)
},
inverseJoinColumns = {
@JoinColumn(name="templateId")
}
)
private Set<Template> template;
/**
*
*/
public Set<Template> getChildren() {
return template;
}
/**
*
*/
public void setChildren(Set<Template> template) {
this.template = template;
}
}
你知道我的代碼有什麼問題嗎?
在此先感謝
需要代碼請謝謝 – Woot4Moo 2012-03-15 18:25:55
@Martin我很擔心你發佈的內容不是你的代碼。那麼,我們怎麼能說出它有什麼問題呢? – 2012-03-15 19:55:40
對不起,我這裏很新,我會盡我所能提高我的提高我的問題 – 2012-03-15 20:19:03