Hi,
I have tried your solution proposal, but unfortunatly it does not work. I do not think what I am trying to do so unusual that Hibernate cannot deal with it.
Basically its a linked list which I would like to map to one database table.
I also tried to change my object model, just to test if this could work.
My class looks like this now.
Code:
public final class SystemEventGroup
{
private long id;
private long eventKey;
private Set parentEventGroups = new HashSet();
private String name;
private String descr;
...
}
This is the mapping I am using:
Code:
<class name="wilken.openshop.core.event.SystemEventGroup" table="system_event_group">
<id name="id" type="long" unsaved-value="-1">
<column name="id" sql-type="int(11)" not-null="true"/>
<generator class="identity"/>
</id>
<property name="eventKey" column="event_key"/>
<set name="parentEventGroups" table="system_event_group">
<key column="parent_key"/>
<one-to-many class="wilken.openshop.core.event.SystemEventGroup"/>
</set>
<property name="name" />
<property name="descr" />
</class>
If I do the schema update I still get this strange sql statement "select from " executed by Hibernate which obviously results in a sql exception.
When trying to store an Object which has a parent the child gets inserted but as soon as the parent should be inserted the following exception is thrown. This will not happen if I use two different classes.
Code:
14:01:06,053 DEBUG [SessionImpl] opened session
14:01:06,053 DEBUG [JDBCTransaction] begin
14:01:06,053 DEBUG [JDBCTransaction] current autocommit status:true
14:01:06,053 DEBUG [JDBCTransaction] disabling autocommit
14:01:06,069 DEBUG [SessionImpl] saving [wilken.openshop.core.event.SystemEventGroup#<null>]
14:01:06,069 DEBUG [EntityPersister] Inserting entity: wilken.openshop.core.event.SystemEventGroup (native id)
14:01:06,069 DEBUG [BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
14:01:06,069 DEBUG [SQL] insert into system_event_group (event_key, name, descr) values (?, ?, ?)
Hibernate: insert into system_event_group (event_key, name, descr) values (?, ?, ?)
14:01:06,069 DEBUG [BatcherImpl] preparing statement
14:01:06,069 DEBUG [EntityPersister] Dehydrating entity: [wilken.openshop.core.event.SystemEventGroup#<null>]
14:01:06,069 DEBUG [LongType] binding '0' to parameter: 1
14:01:06,069 DEBUG [StringType] binding 'event1' to parameter: 2
14:01:06,069 DEBUG [StringType] binding null to parameter: 3
14:01:06,069 DEBUG [BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
14:01:06,069 DEBUG [BatcherImpl] closing statement
14:01:06,069 DEBUG [BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
14:01:06,069 DEBUG [SQL] SELECT LAST_INSERT_ID()
Hibernate: SELECT LAST_INSERT_ID()
14:01:06,069 DEBUG [BatcherImpl] preparing statement
14:01:06,069 DEBUG [EntityPersister] Natively generated identity: 20
14:01:06,069 DEBUG [BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
14:01:06,069 DEBUG [BatcherImpl] closing statement
14:01:06,069 DEBUG [JDBCTransaction] commit
14:01:06,069 DEBUG [SessionImpl] flushing session
14:01:06,069 DEBUG [SessionImpl] Flushing entities and processing referenced collections
14:01:06,100 DEBUG [WrapVisitor] Wrapped collection in role: wilken.openshop.core.event.SystemEventGroup.parentEventGroups
14:01:06,100 DEBUG [SessionImpl] Collection found: [wilken.openshop.core.event.SystemEventGroup.parentEventGroups#20], was: [<unreferenced>]
14:01:06,100 DEBUG [SessionImpl] Processing unreferenced collections
14:01:06,100 DEBUG [SessionImpl] Scheduling collection removes/(re)creates/updates
14:01:06,116 DEBUG [SessionImpl] Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
14:01:06,116 DEBUG [SessionImpl] Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
14:01:06,116 DEBUG [Printer] listing entities:
14:01:06,116 DEBUG [Printer] wilken.openshop.core.event.SystemEventGroup{eventKey=0, descr=null, name=event1, parentEventGroups=[SystemEventGr
14:01:06,116 DEBUG [SessionImpl] executing flush
14:01:06,116 DEBUG [BasicCollectionPersister] Inserting collection: [wilken.openshop.core.event.SystemEventGroup.parentEventGroups#20]
14:01:06,116 DEBUG [BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
14:01:06,116 DEBUG [SQL] update system_event_group set parent_key=? where id=?
Hibernate: update system_event_group set parent_key=? where id=?
14:01:06,116 DEBUG [BatcherImpl] preparing statement
14:01:06,116 DEBUG [LongType] binding '20' to parameter: 1
14:01:06,116 DEBUG [Cascades] id unsaved-value: -1
14:01:06,116 DEBUG [LongType] binding '0' to parameter: 2
14:01:06,116 DEBUG [BatcherImpl] Adding to batch
14:01:06,116 DEBUG [BasicCollectionPersister] done inserting collection: 1 rows inserted
14:01:06,116 DEBUG [BatcherImpl] Executing batch size: 1
14:01:06,131 DEBUG [BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
14:01:06,131 DEBUG [BatcherImpl] closing statement
14:01:06,131 ERROR [SessionImpl] Could not synchronize database state with session
net.sf.hibernate.HibernateException: Batch update row count wrong: 0
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:65)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:118)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2311)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2265)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2187)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at wilken.openshop.test.TestBean.store(TestBean.java:36)
This is really strange, I do not have a clue why.
Any opinion what can be done to solve this problem?
I would like to avoid to adjust my object model in order for Hibernate to be able to work with it.
Thanks for your help.
Best regards,
juergen