我有一张表Book
,只有一个column(book_id)
为Serial
。
我正在使用Informix和openejb 4.7.2。
当我尝试在DB中创建新条目时,我收到错误
OpenEJB - EjbTransactionUtil.handleSystemException: org.hibernate.exception.SQLGrammarException: could not prepare statement
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387) ~[hibernate-entitymanager-4.2.19.Final.jar:4.2.19.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310) ~[hibernate-entitymanager-4.2.19.Final.jar:4.2.19.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1316) ~[hibernate-entitymanager-4.2.19.Final.jar:4.2.19.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:881) ~[hibernate-entitymanager-4.2.19.Final.jar:4.2.19.Final]
at org.apache.openejb.persistence.JtaEntityManager.persist(JtaEntityManager.java:149) ~[openejb-core-4.7.2.jar:4.7.2]
Book.java
@Entity
@Table(name = "book")
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "book_id", nullable = false)
private short bookId;
public short getBookId() {
return bookId;
}
public void setBookId(short bookId) {
this.bookId = bookId;
}
}
public class DocumentTemplateDAO{
@Override
public Book create(Book entity) {
LOG.debug("Entity is created {} ", entity);
this.entityManager.persist(entity);
this.entityManager.flush();
return entity;
}
}
创建图书的代码
Book book = new Book();
documentTemplateDAO.create(book);
将要执行的查询是
insert into book values ( )
答案 0 :(得分:0)
2个可能的解决方案:
Informix SERIAL(如果这是您的图书ID在数据库中)是零触发自动增量,它应该影响@GeneratedValue(strategy = GenerationType.AUTO)。
IBM为Informix开发了一个特定的Hibernate方言,你可以在那里下载:http://members.iiug.org/opensource/。
对不起,我现在没有更多,希望它会让你走上正轨。