Paul Sturrock wrote:OK. Well what should be happening is behind the scenes Hibernate will "Hydrate" the object, where by your mapped type will be populated based on the results on whatever JDBC result set you are using. Given your initial HQL query:
will translate into a SQL query like:
you can be sure (give or take the implementation specifics of whatever database/driver you are using) the state of your ResultSet should not need Hibernate to go back to the database. My guess is the extra selects you are seeing are the result of your association mapping. Can you post your annotated POJOs?
Also, there will be an overhead because you wrap everything in a transaction. I'd ditch that part an only use transactions when updating the data.
Thanks for the reply.
Here are the mapped objects. I've cut everything except the annotated bits as there is a lot of code on them which is nothing to do with Hibernate. Bear in mind that a lot of the fetch types, lazy loading being set or not, @Generated annotations, batch sizes and that sort of thing are only there as a result of me hacking at it today so don't really mean much.
(TransmitterLocation is a class as originally a transmitter could be in multiple places - that requirement is gone now but may resurface, so that one-to-one relation there might change.)
The code I'm using to initialise and refresh things is currently all just a variant on
ie "from X".
When you actually fire it up and it starts loading, with show_sql enabled you see stuff like this :-
Hibernate: select transmitte0_.TX_ID as TX1_5_, transmitte0_.TX_STATUS1 as TX2_5_, transmitte0_.TX_LASTRECD as TX3_5_, transmitte0_.TX_LATEAFTER as TX4_5_, transmitte0_.TX_LOCATION as TX5_5_, transmitte0_.RX_ID as RX7_5_, transmitte0_.TX_ADDRESS as TX6_5_, transmitte0_.TXTYPE_ID as TXTYPE8_5_ from TX transmitte0_
Hibernate: select receiver0_.RX_ID as RX1_6_0_, receiver0_.RX_NAME as RX2_6_0_ from RX receiver0_ where receiver0_.RX_ID=?
Hibernate: select transmitte0_.TXTYPE_ID as TXTYPE1_0_0_, transmitte0_.TXTYPE_NAME as TXTYPE2_0_0_ from TX_TYPE transmitte0_ where transmitte0_.TXTYPE_ID in (?, ?, ?, ?, ?)
Hibernate: select transmitte0_.TX_PLANPLACE_ID as TX1_7_6_, transmitte0_.FLOOR_ID as FLOOR5_7_6_, transmitte0_.TX_PLANPLACE_ORIGINAL_SIZE as TX2_7_6_, transmitte0_.TX_ID as TX6_7_6_, transmitte0_.TX_PLANPLACE_X as TX3_7_6_, transmitte0_.TX_PLANPLACE_Y as TX4_7_6_, floor1_.FLOOR_ID as FLOOR1_3_0_, floor1_.BUILDING_ID as BUILDING2_3_0_, floor1_.FLOOR_TREEINDEX as FLOOR3_3_0_, floor1_.FLOOR_IMAGE_SOURCE as FLOOR4_3_0_, floor1_.FLOOR_NAME as FLOOR5_3_0_, floor1_.FLOOR_ORIGIN_X as FLOOR6_3_0_, floor1_.FLOOR_ORIGIN_Y as FLOOR7_3_0_, floor1_.FLOOR_SCALE_MULTIPLIER as FLOOR8_3_0_, transmitte2_.TX_ID as TX1_5_1_, transmitte2_.TX_STATUS1 as TX2_5_1_, transmitte2_.TX_LASTRECD as TX3_5_1_, transmitte2_.TX_LATEAFTER as TX4_5_1_, transmitte2_.TX_LOCATION as TX5_5_1_, transmitte2_.RX_ID as RX7_5_1_, transmitte2_.TX_ADDRESS as TX6_5_1_, transmitte2_.TXTYPE_ID as TXTYPE8_5_1_, receiver3_.RX_ID as RX1_6_2_, receiver3_.RX_NAME as RX2_6_2_, sensorlist4_.TX_ID as TX7_8_, sensorlist4_.Sensor_ID as Sensor1_8_, sensorlist4_.Sensor_ID as Sensor1_4_3_, sensorlist4_.Sensor_AlmHi as Sensor2_4_3_, sensorlist4_.Sensor_AlmLo as Sensor3_4_3_, sensorlist4_.Sensor_PncHi as Sensor4_4_3_, sensorlist4_.Sensor_PncLo as Sensor5_4_3_, sensorlist4_.TX_ID as TX7_4_3_, sensorlist4_.SType_ID as SType8_4_3_, sensorlist4_.Sensor_LastValue as Sensor6_4_3_, sensortype5_.STYPE_ID as STYPE1_1_4_, sensortype5_.SType_EU as SType2_1_4_, sensortype5_.SType_Format as SType3_1_4_, sensortype5_.SType_MaxValue as SType4_1_4_, sensortype5_.SType_MinValue as SType5_1_4_, sensortype5_.SType_Type as SType6_1_4_, transmitte6_.TXTYPE_ID as TXTYPE1_0_5_, transmitte6_.TXTYPE_NAME as TXTYPE2_0_5_ from TX_PLANPLACE transmitte0_ inner join FLOOR floor1_ on transmitte0_.FLOOR_ID=floor1_.FLOOR_ID inner join TX transmitte2_ on transmitte0_.TX_ID=transmitte2_.TX_ID left outer join RX receiver3_ on transmitte2_.RX_ID=receiver3_.RX_ID left outer join Sensor sensorlist4_ on transmitte2_.TX_ID=sensorlist4_.TX_ID left outer join Sensor_Type sensortype5_ on sensorlist4_.SType_ID=sensortype5_.STYPE_ID left outer join TX_TYPE transmitte6_ on transmitte2_.TXTYPE_ID=transmitte6_.TXTYPE_ID where transmitte0_.TX_ID=?
etc.etc.etc.
There are a lot of joins in there, as I've been playing with FetchType. It does make it a bit faster doing it that way, but its still far too slow.
SensorType and maybe TransmitterLocation could be (should be?) @Embeddable I imagine, not sure if that is involved with this problem though.