- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 table 上做了一个“简单的”,它给出了这个错误。搜索网络没有帮助。
我认为使用序列作为我的主键源与我有关。
你能帮忙吗?谢谢
我正在尝试运行的代码(我已经突出显示了引发错误的部分)
EventInstance eventInstance = (EventInstance) sessionFactory.getCurrentSession().get(EventInstance.class, userEventRegistration.getEventInstance().getInstanceId());
Student student = (Student) sessionFactory.getCurrentSession().get(Student.class, userEventRegistration.getStudent().getStudentId());
EventRegistration eventRegistration = new EventRegistration();
if (student == null) {
student = new Student();
student.setStudentId(userEventRegistration.getStudent().getStudentId());
}
student.setFamilyName(userEventRegistration.getStudent().getFamilyName());
student.setGivenName(userEventRegistration.getStudent().getGivenName());
student.setGender(userEventRegistration.getStudent().getGender());
student.setEmail(userEventRegistration.getStudent().getEmail());
student.setHomeCountry(userEventRegistration.getStudent().getHomeCountry());
student.setCourse(userEventRegistration.getStudent().getCourse());
student.setAccomodationName(userEventRegistration.getStudent().getAccomodationName());
student.setAddress(userEventRegistration.getStudent().getAddress());
student.setAddressCity(userEventRegistration.getStudent().getAddressCity());
student.setContactPhone(userEventRegistration.getStudent().getContactPhone());
student.setContactDetailsStatus(userEventRegistration.getStudent().getContactDetailsStatus());
student.setContactDetailsDate(userEventRegistration.getStudent().getContactDetailsDate());
student.setScholarships(userEventRegistration.getStudent().getScholarships());
student.setDietaryRestrictions(userEventRegistration.getStudent().getDietaryRestrictions());
student.setStudentComments(userEventRegistration.getStudent().getStudentComments());
student.setInternalComments(userEventRegistration.getStudent().getInternalComments());
eventRegistration.setEventInstance(eventInstance);
eventRegistration.setStudent(student);
eventRegistration.setAttended(userEventRegistration.getAttended());
eventRegistration.setSubmitDateTime(new Date());
eventRegistration.setAdditionalInfo(userEventRegistration.getAdditionalInfo());
eventRegistration.setNumberAttending(userEventRegistration.getNumberAttending());
eventRegistration.setArchiveDate(userEventRegistration.getArchiveDate());
**sessionFactory.getCurrentSession().save(eventRegistration);**
sessionFactory.getCurrentSession().getTransaction().commit();
hibernate 映射
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.myapps.issu.models.database.Event" table="events">
<id name="eventId" column="event_id" type="integer" />
<property name="eventName" column="event_name" type="string" />
<property name="eventType" column="event_type" type="string" />
<property name="descriptionBrief" column="description_brief" type="string" />
<property name="descriptionFull" column="description_full" type="string" />
<property name="location" column="location" type="string" />
<property name="cost" column="cost" type="string" />
<property name="compulsory" column="compulsory" type="string" />
<property name="comments" column="comments" type="string" />
<property name="maxAttendance" column="max_attendance" type="integer" />
<property name="askDietaryRestrictions" column="ask_dietary_restrictions" type="integer" />
<property name="limitPerStudent" column="limit_per_student" type="string" />
<list name="eventInstance" table="event_instances" inverse="false" cascade="all">
<key column="event_id" />
<list-index column="idx" />
<one-to-many class="com.myapps.issu.models.database.EventInstance" />
</list>
</class>
<class name="com.myapps.issu.models.database.Student" table="students">
<id name="studentId" column="student_id" type="string" />
<property name="familyName" column="family_name" type="string" />
<property name="givenName" column="given_name" type="string" />
<property name="fan" column="fan" type="string" />
<property name="gender" column="gender" type="string" />
<property name="email" column="email" type="string" />
<property name="homeCountry" column="home_country" type="string" />
<property name="course" column="course" type="string" />
<property name="accomodationName" column="accomodation_name" type="string" />
<property name="address" column="address" type="string" />
<property name="addressCity" column="address_city" type="string" />
<property name="contactPhone" column="contact_phone" type="string" />
<property name="contactDetailsStatus" column="contact_details_status" type="string" />
<property name="contactDetailsDate" column="contact_details_date" type="date" />
<property name="scholarships" column="scholarships" type="string" />
<property name="dietaryRestrictions" column="dietary_restrictions" type="string" />
<property name="studentComments" column="student_comments" type="string" />
<property name="internalComments" column="internal_comments" type="string" />
<list name="eventRegistration" table="event_registrations" inverse="false" cascade="all">
<key column="registration_id" />
<list-index column="idx" />
<one-to-many class="com.myapps.issu.models.database.EventRegistration" />
</list>
</class>
<class name="com.myapps.issu.models.database.EventInstance" table="event_instances">
<id name="instanceId" column="instance_id" type="integer" />
<many-to-one name="event" class="com.myapps.issu.models.database.Event" column="event_id" fetch="select" not-null="true" />
<property name="startDateTime" column="start_date_time" type="date" />
<property name="finishDateTime" column="finish_date_time" type="date" />
<property name="locationIfDifferent" column="location_if_different" type="string" />
<property name="registerCutoffDate" column="register_cutoff_date" type="date" />
<property name="maxAttendance" column="max_attendance" type="integer" />
<property name="askDietaryRestrictions" column="ask_dietary_restrictions" type="string" />
<property name="limitPerStudent" column="limit_per_student" type="integer" />
<property name="archiveDate" column="archive_date" type="date" />
<property name="rollcallProcessed" column="rollcall_processed" type="string" />
<property name="linkedInstance" column="linked_instance" type="integer" />
<list name="eventRegistration" table="event_registrations" inverse="false" cascade="all">
<key column="instance_id" />
<list-index column="idx" />
<one-to-many class="com.myapps.issu.models.database.EventInstance" />
</list>
</class>
<class name="com.myapps.issu.models.database.EventRegistration" table="event_registrations">
<id name="registrationId" column="registration_id" type="integer">
<generator class="sequence-identity" >
<param name="sequence">REGISTRATIONS_SEQ</param>
</generator>
</id>
<many-to-one name="eventInstance" class="com.myapps.issu.models.database.EventInstance" column="instance_id" not-null="true" />
<many-to-one name="student" class="com.myapps.issu.models.database.Student" column="student_id" not-null="true" />
<property name="attended" column="attended" type="string" />
<property name="submitDateTime" column="submit_date_time" type="date" />
<property name="additionalInfo" column="additional_info" type="string" />
<property name="numberAttending" column="number_attending" type="integer" />
<property name="archiveDate" column="archive_date" type="date" />
</class>
<class name="com.myapps.issu.models.database.Lov" table="Lov">
<id name="lovId" column="lov_id" type="integer" />
<property name="kind" column="kind" type="string" />
<property name="code" column="code" type="string" />
<property name="description" column="description" type="string" />
</class>
</hibernate-mapping>
错误信息
org.hibernate.AssertionFailure: getGeneratedKeys() support is not enabled
org.hibernate.engine.jdbc.internal.StatementPreparerImpl.checkAutoGeneratedKeysSupportEnabled(StatementPreparerImpl.java:93)
org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:112)
org.hibernate.id.SequenceIdentityGenerator$Delegate.prepare(SequenceIdentityGenerator.java:106)
org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:55)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2936)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3447)
org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:203)
org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:183)
org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:167)
org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:320)
org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:287)
org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:193)
org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:204)
org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:189)
org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:756)
org.hibernate.internal.SessionImpl.save(SessionImpl.java:748)
org.hibernate.internal.SessionImpl.save(SessionImpl.java:744)
au.edu.flinders.issu.dao.IssuDaoImpl.saveEventRegistration(IssuDaoImpl.java:64)
au.edu.flinders.issu.services.IssuServiceImpl.saveEventRegistration(IssuServiceImpl.java:24)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
$Proxy13.saveEventRegistration(Unknown Source)
au.edu.flinders.issu.controllers.IssuController.saveEventRegistration(IssuController.java:41)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:604)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:565)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
最佳答案
我遇到了同样的问题。终于找到了出路。将此行放入您的 hibernate.cfg.xml 文件中。
<property name="hibernate.jdbc.use_get_generated_keys">true</property>
可以在以下位置找到引用和解释:
关于hibernate - org.hibernate.AssertionFailure : getGeneratedKeys() support is not enabled (using Oracle11g),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14452602/
我想获取持久对象的 ID。我正在使用 EJB 3.1。 我使用准备好的语句来执行此操作并且效果很好。 ResultSet generatedKeys = statement.getGeneratedK
我将 executeBatch() 与 JDBC 一起使用来插入多行,我想获取插入行的 ID 以进行另一次插入 我为此目的使用此代码: insertInternalStatement = dbConn
我在 try-with-resources 语句中使用了 java 准备语句来访问表 在带有 NetBeans 8.0 IDE 的 Java DB 数据库中。运行 executeUpdate 方法后,
我正在升级到 Grails 2.3.9 的 Hibernate4:4.3.5.3 插件。但是,我收到一个错误: getGeneratedKeys() support is not enabled 我无
我正在尝试做一些在我使用过的每个数据库中都有效的事情。我想从插入中获取生成的 key 。我有 oracle 12c 设置并有下表: CREATE TABLE countyUsers (id integ
这段代码片段 PreparedStatement statement = connect.prepareStatement( query, Statement.RETURN_GEN
我已经了解到 mysql 中的 last_insert_id 不是池安全的。也就是说,如果你正在合并连接,你会弄乱 insert_ids。java 的 statement.getGeneratedKe
我最近从 MySQL 切换到 PostgreSQL 用于项目的后端,并发现我的一些数据库代理方法需要审查。为了插入链接对象,我使用事务来确保所有内容都已存储。我使用诸如 setAutoCommit(f
好的,我错过了什么? 我有这样一张表: CREATE TABLE PUBLIC.RESULTS (RESULTID IDENTITY NOT NULL, SOURCEID INTEGER NOT NU
我想使用 PreparedStatement INSERT 几行: ps = con.prepareStatement(query,PreparedStatement.RETURN_GENERATED
我有一个表,其中有一列定义为自动生成键。执行以下代码时,我希望生成一个新 key ,但事实并非如此。插入一行,但 ps.getGeneratedKeys() 的结果集为空。 我正在使用 DB2:SQL
我希望 JDBI 将自动生成的主键(Long 值)转换为另一个类。 我的 DAO: @RegisterMapper(SystemIdMapper.class) public interface Sys
preparedStatement.getGeneratedKeys() 在查询只有一个 INSERT MySQL 语句时工作正常,但如果查询中有多个语句,它不会返回生成的 ID,即: test 有
我创建的表是这样的: public final String CREATE_QUESTIONS_TABLE = "CREATE TABLE Questions(QuestionID INTEGER P
我正在玩 JDBC/MySQL 5.1。我创建了一个 insert 查询来将一些数据插入到表中,并希望从新创建的行中返回生成的键。但是,当我通过“id”引用列时,这是我的 PK 和自动递增列。 Pre
Python的sqlite3模块中有没有类似于Java的statement.getGeneratedKeys()的API?如果没有,使用 sqlite3 在 Python 中获取最近自动生成的 key
我想使用插入查询检索表中最近更新的值。 这些是我的 sql 表中的数据类型。 数据类型: int(11) // primary key auto increment, not being a
我在 table 上做了一个“简单的”,它给出了这个错误。搜索网络没有帮助。 我认为使用序列作为我的主键源与我有关。 你能帮忙吗?谢谢 我正在尝试运行的代码(我已经突出显示了引发错误的部分)
我正在使用 JDBC 向 MYSQL 数据库中插入一行。我构建了一个参数化命令,执行它并尝试检索自动生成的 key ,如下所示: String sql = "INSERT IGNORE INTO `u
我有一个查询如下: String SQL = "insert into table (id, name) values (sequence.nextval, ?)"; 然后我像这样制作一个 Prepa
我是一名优秀的程序员,十分优秀!