Ok, I have upgradet to hibernate 3 and done a first test with this new Device.hbm.xml.
I have a question about the documentation of hibernate 2 anyway:
It is even possible to use different mapping strategies for different branches of the same inheritance hierarchy, but the same limitations apply as apply to table-per-concrete class mappings. Hibernate does not support mixing <subclass> mappings and <joined-subclass> mappings inside the same <class> element.
Doesn't that mean the mapping in the original post is correct? As far as I understand the documentation I just can not use different mapping strategies in the same branch of the inheritance hierarchy. Meaning that I can not have one Sub of Base mapped in a joined-subclass and the other one in subclass.
About the current mapping It looks unnaturally to me that I have to join the table to the Net_printer class as it belongs more to the IPrinter interface. But if I try to join the IPrinter I get a complained and I can not use both in the same subclass.
If I run the current mapping However I do get a dead-lock inserting a new record.
Device.hbm.xml
<hibernate-mapping package="lanox.core">
<class name="Device"
table="devices" >
<id name="id" column="id" type="long" unsaved-value="0">
<generator class="increment"/>
</id>
<discriminator column="system_oid" type="string"/>
<property name="asset" column="asset" type="long"/>
<property name="serial" column="serial" type="string"/>
<property name="allocation" column="allocation" type="string"/>
<property name="row_insert" column="row_insert" type="timestamp"/>
<property name="row_update" column="row_update" type="timestamp"/>
<property name="invalidate_cnt" column="invalidate_cnt" type="long"/>
<component name="base" class="BaseDevice">
<property name="name" column="name" type="string"/>
<property name="dns_name" column="dns_name" type="string"/>
<property name="mac" column="mac" type="string" />
<one-to-one name="snmpParameters" class="SnmpParameters" cascade="all" />
</component>
<one-to-one name="address" class="DeviceIPAddress" cascade="all"/>
<subclass name="lanox.core.IPrinter">
<subclass name="lanox.snmp.implementations.Net_printer" discriminator-value=".1.3.6.1.4.1.11.2.3.9.1">
<join table="printer">
<key column="id"/>
<property name="description" column="description" type="string" />
</join>
</subclass>
</subclass>
<subclass name="IMultiportDevice">
<map name="ports" order-by="port_id, group_id" cascade="all-delete-orphan" table="ports" >
<key column="device_id"/>
<composite-index class="lanox.core.PortKey">
<key-property name="port_id" column="port_id" />
<key-property name="group_id" column="group_id" />
</composite-index>
<one-to-many class="Port"/>
</map>
<join table="multiport_devices">
<key column="id"/>
</join>
</subclass>
</class>
</hibernate-mapping>
Stack trace
14:39:18,208 DEBUG JDBCTransaction:46 - begin
14:39:18,208 DEBUG JDBCTransaction:50 - current autocommit status: false
14:39:18,208 DEBUG DefaultSaveOrUpdateEventListener:159 - saving transient instance
14:39:18,208 DEBUG IncrementGenerator:65 - fetching initial value: select max(id) from devices
14:39:18,223 DEBUG IncrementGenerator:81 - first free id: 1
14:39:18,223 DEBUG AbstractSaveEventListener:89 - generated identifier: 1, using strategy: org.hibernate.id.IncrementGenerator
14:39:18,223 DEBUG AbstractSaveEventListener:132 - saving [lanox.snmp.implementations.Net_printer#1]
14:39:18,223 DEBUG Cascades:806 - processing cascade ACTION_SAVE_UPDATE for: lanox.snmp.implementations.Net_printer
14:39:18,239 DEBUG Cascades:831 - done processing cascade ACTION_SAVE_UPDATE for: lanox.snmp.implementations.Net_printer
14:39:18,255 DEBUG Cascades:806 - processing cascade ACTION_SAVE_UPDATE for: lanox.snmp.implementations.Net_printer
14:39:18,255 DEBUG Cascades:152 - cascading to saveOrUpdate: lanox.core.SnmpParameters
14:39:18,270 DEBUG Cascades:525 - id unsaved-value: 0
14:39:18,270 DEBUG AbstractSaveEventListener:408 - transient instance of: lanox.core.SnmpParameters
14:39:18,270 DEBUG DefaultSaveOrUpdateEventListener:159 - saving transient instance
14:39:18,270 DEBUG AbstractSaveEventListener:89 - generated identifier: 1, using strategy: org.hibernate.id.ForeignGenerator
14:39:18,270 DEBUG AbstractSaveEventListener:132 - saving [lanox.core.SnmpParameters#1]
14:39:18,270 DEBUG Cascades:152 - cascading to saveOrUpdate: lanox.core.DeviceIPAddress
14:39:18,270 DEBUG Cascades:525 - id unsaved-value: 0
14:39:18,270 DEBUG AbstractSaveEventListener:408 - transient instance of: lanox.core.DeviceIPAddress
14:39:18,270 DEBUG DefaultSaveOrUpdateEventListener:159 - saving transient instance
14:39:18,270 DEBUG AbstractSaveEventListener:89 - generated identifier: 1, using strategy: org.hibernate.id.ForeignGenerator
14:39:18,286 DEBUG AbstractSaveEventListener:132 - saving [lanox.core.DeviceIPAddress#1]
14:39:18,286 DEBUG Cascades:831 - done processing cascade ACTION_SAVE_UPDATE for: lanox.snmp.implementations.Net_printer
14:39:18,286 DEBUG JDBCTransaction:83 - commit
14:39:18,286 DEBUG SessionImpl:292 - automatically flushing session
14:39:18,286 DEBUG AbstractFlushingEventListener:52 - flushing session
14:39:18,286 DEBUG AbstractFlushingEventListener:102 - processing flush-time cascades
14:39:18,286 DEBUG Cascades:806 - processing cascade ACTION_SAVE_UPDATE for: lanox.snmp.implementations.Net_printer
14:39:18,286 DEBUG Cascades:152 - cascading to saveOrUpdate: lanox.core.SnmpParameters
14:39:18,286 DEBUG AbstractSaveEventListener:392 - persistent instance of: lanox.core.SnmpParameters
14:39:18,286 DEBUG DefaultSaveOrUpdateEventListener:103 - ignoring persistent instance
14:39:18,301 DEBUG DefaultSaveOrUpdateEventListener:140 - object already associated with session: [lanox.core.SnmpParameters#1]
14:39:18,301 DEBUG Cascades:152 - cascading to saveOrUpdate: lanox.core.DeviceIPAddress
14:39:18,301 DEBUG AbstractSaveEventListener:392 - persistent instance of: lanox.core.DeviceIPAddress
14:39:18,301 DEBUG DefaultSaveOrUpdateEventListener:103 - ignoring persistent instance
14:39:18,301 DEBUG DefaultSaveOrUpdateEventListener:140 - object already associated with session: [lanox.core.DeviceIPAddress#1]
14:39:18,301 DEBUG Cascades:831 - done processing cascade ACTION_SAVE_UPDATE for: lanox.snmp.implementations.Net_printer
14:39:18,301 DEBUG AbstractFlushingEventListener:150 - dirty checking collections
14:39:18,301 DEBUG AbstractFlushingEventListener:167 - Flushing entities and processing referenced collections
14:39:18,301 DEBUG BasicEntityPersister:2575 - lanox.snmp.implementations.Net_printer.row_insert is dirty
14:39:18,317 DEBUG DefaultFlushEntityEventListener:121 - Updating entity: [lanox.snmp.implementations.Net_printer#1]
14:39:18,317 DEBUG AbstractFlushingEventListener:203 - Processing unreferenced collections
14:39:18,317 DEBUG AbstractFlushingEventListener:217 - Scheduling collection removes/(re)creates/updates
14:39:18,317 DEBUG AbstractFlushingEventListener:79 - Flushed: 3 insertions, 1 updates, 0 deletions to 3 objects
14:39:18,317 DEBUG AbstractFlushingEventListener:85 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
14:39:18,317 DEBUG Printer:83 - listing entities:
14:39:18,348 DEBUG Printer:90 - lanox.core.SnmpParameters{device=lanox.core.Device#1, write_community=public, read_community=public, system_oid=.1.3.6.1.4.1.11.2.3.9.1, id=1}
14:39:18,380 DEBUG Printer:90 - lanox.snmp.implementations.Net_printer{base=component[name,dns_name,mac,snmpParameters]{dns_name=ost0007.ost.eur.webdti.com, snmpParameters=lanox.core.SnmpParameters#1, name=null, mac=00-60-b0-ad-7e-ce}, allocation=STATIC, invalidate_cnt=0, row_insert=2005-03-02 14:39:18, asset=0, row_update=2005-03-02 14:39:18, description=null, address=lanox.core.DeviceIPAddress#1, id=1, serial=null}
14:39:18,395 DEBUG Printer:90 - lanox.core.DeviceIPAddress{device=lanox.core.Device#1, ip_c=33, ip_a=153, ip_b=115, ip_d=7, id=1}
14:39:18,395 DEBUG AbstractFlushingEventListener:267 - executing flush
14:39:18,395 DEBUG BasicEntityPersister:1795 - Inserting entity: [lanox.snmp.implementations.Net_printer#1]
14:39:18,395 DEBUG AbstractBatcher:258 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
14:39:18,395 DEBUG SQL:292 - /*insert lanox.snmp.implementations.Net_printer*/insert into devices (asset, serial, allocation, row_insert, row_update, invalidate_cnt, name, dns_name, mac, system_oid, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, '.1.3.6.1.4.1.11.2.3.9.1', ?)
Hibernate: /*insert lanox.snmp.implementations.Net_printer*/insert into devices (asset, serial, allocation, row_insert, row_update, invalidate_cnt, name, dns_name, mac, system_oid, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, '.1.3.6.1.4.1.11.2.3.9.1', ?)
14:39:18,395 DEBUG AbstractBatcher:343 - preparing statement
14:39:18,395 DEBUG BasicEntityPersister:1587 - Dehydrating entity: [lanox.snmp.implementations.Net_printer#1]
14:39:18,411 DEBUG LongType:59 - binding '0' to parameter: 1
14:39:18,411 DEBUG StringType:52 - binding null to parameter: 2
14:39:18,411 DEBUG StringType:59 - binding 'STATIC' to parameter: 3
14:39:18,411 DEBUG TimestampType:59 - binding '2005-03-02 14:39:18' to parameter: 4
14:39:18,426 DEBUG TimestampType:52 - binding null to parameter: 5
14:39:18,426 DEBUG LongType:59 - binding '0' to parameter: 6
14:39:18,426 DEBUG StringType:52 - binding null to parameter: 7
14:39:18,442 DEBUG StringType:59 - binding 'ost0007.ost.eur.webdti.com' to parameter: 8
14:39:18,442 DEBUG StringType:59 - binding '00-60-b0-ad-7e-ce' to parameter: 9
14:39:18,442 DEBUG LongType:59 - binding '1' to parameter: 10
14:39:18,442 DEBUG AbstractBatcher:27 - Adding to batch
14:39:18,442 DEBUG BasicEntityPersister:1795 - Inserting entity: [lanox.snmp.implementations.Net_printer#1]
14:39:18,442 DEBUG AbstractBatcher:54 - Executing batch size: 1
14:40:09,723 DEBUG AbstractBatcher:266 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
14:40:09,723 DEBUG AbstractBatcher:363 - closing statement
14:40:09,723 DEBUG JDBCExceptionReporter:49 - Could not execute JDBC batch update [/*insert lanox.snmp.implementations.Net_printer*/insert into devices (asset, serial, allocation, row_insert, row_update, invalidate_cnt, name, dns_name, mac, system_oid, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, '.1.3.6.1.4.1.11.2.3.9.1', ?)]
java.sql.BatchUpdateException: Deadlock found when trying to get lock; Try restarting transaction message from server: "Lock wait timeout exceeded; try restarting transaction"
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1492)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:154)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:71)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:66)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1812)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2171)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:293)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at lanox.collectors.DiscoveryThread.processNewDevice(DiscoveryThread.java:211)
at lanox.collectors.DiscoveryThread.run(DiscoveryThread.java:81)
at lanox.test.DiscoveryTest.test_singlethreaded(DiscoveryTest.java:62)
at lanox.test.DiscoveryTest.main(DiscoveryTest.java:67)
14:40:09,739 WARN JDBCExceptionReporter:57 - SQL Error: 1205, SQLState: 41000
14:40:09,739 ERROR JDBCExceptionReporter:58 - Deadlock found when trying to get lock; Try restarting transaction message from server: "Lock wait timeout exceeded; try restarting transaction"
14:40:09,739 ERROR AbstractFlushingEventListener:277 - Could not synchronize database state with session
org.hibernate.exception.LockAcquisitionException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:77)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:161)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:71)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:66)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1812)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2171)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:293)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at lanox.collectors.DiscoveryThread.processNewDevice(DiscoveryThread.java:211)
at lanox.collectors.DiscoveryThread.run(DiscoveryThread.java:81)
at lanox.test.DiscoveryTest.test_singlethreaded(DiscoveryTest.java:62)
at lanox.test.DiscoveryTest.main(DiscoveryTest.java:67)
Caused by: java.sql.BatchUpdateException: Deadlock found when trying to get lock; Try restarting transaction message from server: "Lock wait timeout exceeded; try restarting transaction"
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1492)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:154)
... 17 more
14:40:09,786 ERROR collectors:97 - Hibernate exception:
14:40:09,786 ERROR collectors:97 - Hibernate exception:
14:40:09,786 ERROR collectors:98 - Could not execute JDBC batch update
14:40:09,786 ERROR collectors:98 - Could not execute JDBC batch update
|