如何使用休眠插入新项目?
我有一个名为在休眠状态下映射的实体类。Task
我能够正确获取属于这个类的现有项目,所以我认为这不是类映射的问题。
但是,当我尝试插入新项目时,我收到以下错误:
org.hibernate.exception.SQLGrammarException: error performing isolated work
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:80)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
at org.hibernate.engine.transaction.internal.jdbc.JdbcIsolationDelegate.delegateWork(JdbcIsolationDelegate.java:96)
at org.hibernate.id.enhanced.TableStructure$1.getNextValue(TableStructure.java:131)
at org.hibernate.id.enhanced.NoopOptimizer.generate(NoopOptimizer.java:58)
at org.hibernate.id.enhanced.SequenceStyleGenerator.generate(SequenceStyleGenerator.java:422)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:117)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:114)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:680)
at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:672)
在下面的代码中:
Task t = new Task();
t.title = "foo";
t.comment = "bar";
//snip... (every single field of task is given some value, except for id)
session.saveOrUpdate("Task", t); //This is the line on which the exception occurs
如果我不这样做,那么新任务不会插入到数据库中。saveOrUpdate()
我做错了什么?
编辑:也不起作用session.save(task)