我正在使用mysql和ecliselink构建基于JPA的应用程序。当我尝试将东西插入我的数据库时,我有一个非常奇怪的问题。我能够将数据插入到单个表中但是当它涉及到一对一时,反之亦然出现问题。目前我有2个主表和1个引用表(它保存了另外两个表的外键)。这很奇怪,因为我的数据库表中没有“序列”当我尝试将数据插入到我的任何一个表中时表格我得到了这个例外:
[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;
}
}
你知道我的代码有什么问题吗?
提前致谢
答案 0 :(得分:2)
查看代码有助于找出问题所在。但是,通过仅判断错误消息,您似乎选择使用序列或表生成器,并且此生成器(默认情况下)依赖于名为sequence
的表,该表在数据库中不存在。 / p>
创建此表,或将生成器配置为使用现有表,或更改ID生成器。