hi,
I'm getting very strange behaviour (using 3.1.3, but even with the most current version: 3.2.0.cr2) and I hope there's something obvious I've missed
summary:
* adding/removing mappings for POJOs that are never even used makes Hibernate throw an exception
* executing the exact same finder (after just having created some entities) in a different session makes Hibernate throw an exception
I'm a bit reluctant to post all my mappings and code because it would make this post very long; anyway I'll try to describe the problem and perhaps someone out there has had a similar problem
object model:* 3 separate hierarchies of union-subclass inheritance
* hierarchies share a few relationships
* all POJOs are immutable Java classes, member fields are private
* using Java5 generics on associations
* hsqldb in-memory (the problem arises during unit testing), hibernate.hbm2ddl.auto=create-drop; using the HSQLDB dialect
mappings:execution A (works fine):* configure programmatically
* build sessionfactory
* open session
* start transaction
* create a few objects
* commit transaction
* try to find objects
* close session
this works fine as expected, however (notice a and b):
execution B (throws exception, different finder query in step 7):* configure programmatically
* build sessionfactory
* open session
* start transaction
* create a few objects
* commit transaction
* a. close session
* b. open new session
* try to find objects
* close session
this yields a problem during the finder where the exception says:
org.hibernate.PropertyAccessException: could not set a field value by reflection setter of ntc.nms.framework.configuration.SimpleManagedObject.invalid('invalid' is a primitive boolean property, which is mapped with not-null="true", also note that my schema is dropped-created on each run so there's nothing left from a previous run)
I've traced this problem down to a certain SQL query which contains the following fragment:
..., null as INVALID, null as ALGORITHM, ID, null ... (actual query is very long, I've just pasted the relevant portion)
as far as I understand this is the union-subclass mapping doing a table scan using 'union' in order to find the specific object instances matching my query (I'm trying to find objects which match a value from a set of identifiers)
now the problem is that the query succeeds fine, but when 'hydrating' the POJO Hibernate attemps to set 'null' into a primitive field, even though that field has explicitely been set to not-null="true", and while doing so an exception occurs since this is something which cannot be done
execution C (works fine too):when I remove all mappings, except the ones for the classes being used, then it works too
execution D (works fine too):if all my relationships are fetched lazily then it also works, I've not tested this extensively since working this way isn't an option and I'm running out of time :-/
questions:* can someone explain to me why a finder would behave this way in a different session ?
* why is the SQL query different ? remember, execution A works fine!
* why would a working query be broken by adding a single mapping which would never be used (mapping could even contain no properties or associations, just the POJO name)
I would really want to understand what's going on here ..
thanks in advance!