Does use of the native identifier generation cause a commit to the database even when the connection's autocommit is set to false? When doing a save on an entity inside a transaction, it gets saved to the database even when I invoke rollback instead of commit. Hibernate does an insert to get the database-generated identifier, but that insert is not undone when I call rollback after the save.
Hibernate version: 3.0
Mapping documents:
<hibernate-mapping>
<class name="uexp.model.Venue" table="venues">
<id name="venueKey" column="venue_id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="venueId" column="uid" type="uexp.dao.impl.hibernate.UidUserType" not-null="true" unique="true" access="field"/>
<property name="name" column="name" not-null="true"/>
<property name="address" column="address"/>
<property name="phone" column="phone"/>
<many-to-one name="parent" column="parent" class="uexp.model.Venue" access="field"/>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
tx = session.beginTransaction();
session.save(venue);
tx.rollback();
Full stack trace of any exception that occurs:
Name and version of the database you are using: MySQL 4.0.20a
The generated SQL (show_sql=true): insert into venues (uid, name, address, phone, parent) values (?, ?, ?, ?, ?)
Debug level Hibernate log excerpt:
2005-07-05 23:18:07,696 -DEBUG- [in] {JDBCTransaction} begin
2005-07-05 23:18:07,696 -DEBUG- [in] {JDBCTransaction} current autocommit status: false
2005-07-05 23:18:07,696 -DEBUG- [in] {DefaultSaveOrUpdateEventListener} saving transient instance
2005-07-05 23:18:07,696 -DEBUG- [in] {AbstractSaveEventListener} generated identifier: , using strategy: org.hibernate.id.IdentityGenerator
2005-07-05 23:18:07,696 -DEBUG- [in] {AbstractSaveEventListener} saving [uexp.model.Venue#<null>]
2005-07-05 23:18:07,696 -DEBUG- [in] {AbstractSaveEventListener} executing insertions
2005-07-05 23:18:07,696 -DEBUG- [in] {BasicEntityPersister} Inserting entity: uexp.model.Venue (native id)
2005-07-05 23:18:07,696 -DEBUG- [in] {AbstractBatcher} about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2005-07-05 23:18:07,696 -DEBUG- [in] {SQL} insert into venues (uid, name, address, phone, parent) values (?, ?, ?, ?, ?)
2005-07-05 23:18:07,696 -DEBUG- [in] {AbstractBatcher} preparing statement
2005-07-05 23:18:07,696 -DEBUG- [in] {BasicEntityPersister} Dehydrating entity: [uexp.model.Venue#<null>]
2005-07-05 23:18:07,706 -DEBUG- [in] {IdentifierGeneratorFactory} Natively generated identity: 1022
2005-07-05 23:18:07,706 -DEBUG- [in] {AbstractBatcher} about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2005-07-05 23:18:07,706 -DEBUG- [in] {AbstractBatcher} closing statement
2005-07-05 23:18:07,706 -DEBUG- [in] {JDBCTransaction} rollback
2005-07-05 23:18:07,706 -DEBUG- [in] {JDBCContext} before transaction completion
2005-07-05 23:18:07,706 -DEBUG- [in] {SessionImpl} before transaction completion
2005-07-05 23:18:07,706 -DEBUG- [in] {JDBCTransaction} rolled back JDBC Connection
2005-07-05 23:18:07,706 -DEBUG- [in] {JDBCContext} after transaction completion
2005-07-05 23:18:07,706 -DEBUG- [in] {SessionImpl} after transaction completion
2005-07-05 23:18:08,146 -DEBUG- [in] {SessionImpl} closing session
2005-07-05 23:18:08,146 -DEBUG- [in] {ConnectionManager} closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2005-07-05 23:18:08,146 -DEBUG- [in] {JDBCContext} after transaction completion
2005-07-05 23:18:08,146 -DEBUG- [in] {SessionImpl} after transaction completion
2005-07-05 23:18:08,146 -INFO - [in] {VenueManager} Saved venue with uid = 9e7d8004eacb47d0
|