Problem is as follows: I have a legacy oracle db structure (that may not be changed). All the relevant tables do not have PK's and all the tables' are nullable (don't know if that's relevant).
I want to use Hibernate as a simple read-only facade to the database. When I use the hibernatetools (eclipse plugin) to generate code, i get sensible results (unfortunately I cannot attach full code/db configuration because of confidentiality). The mapping file contains a composite key containing all the columns of the DB. The Java files seem to be generated correctly - there are setters and getters for the PK in the main class and the PK class implements equals and hashCode.
Hibernate version: 3.1.3
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Code:
s.beginTransaction();
Query q = s.createQuery("from MvdFpExtr as fp where fp.id.objSid = 7071642");
List list = q.list();
s.getTransaction().commit();
That returns a list where list.size == 1 and list.iterator().next() == null.
If I do a query that should return a number of elements, I get the correct size list but all items are null.
Name and version of the database you are using:Oracle 9i 9.2.0.7.0
Debug level Hibernate log excerpt:Code:
06.06.2006 15:46:31,723 [DEBUG] org.hibernate.loader.Loader : processing result set
06.06.2006 15:46:31,723 [DEBUG] org.hibernate.loader.Loader : result set row: 0
06.06.2006 15:46:31,754 [DEBUG] org.hibernate.type.BigDecimalType : returning '46' as column: JOB1_0_
06.06.2006 15:46:31,754 [DEBUG] org.hibernate.type.LongType : returning '7071642' as column: OBJ2_0_
06.06.2006 15:46:31,754 [DEBUG] org.hibernate.type.ByteType : returning '1' as column: OBJ3_0_
--snip--
Code:
06.06.2006 15:46:31,754 [DEBUG] org.hibernate.type.StringType : returning null as column: EXTERNAL11_0_
06.06.2006 15:46:31,754 [DEBUG] org.hibernate.loader.Loader : result row: null
06.06.2006 15:46:31,801 [DEBUG] org.hibernate.loader.Loader : done processing result set (1 rows)
06.06.2006 15:46:31,816 [DEBUG] org.hibernate.jdbc.AbstractBatcher : about to close ResultSet (open ResultSets: 1, globally: 1)
06.06.2006 15:46:31,816 [DEBUG] org.hibernate.jdbc.AbstractBatcher : about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
06.06.2006 15:46:31,816 [DEBUG] org.hibernate.jdbc.AbstractBatcher : closing statement
06.06.2006 15:46:31,848 [DEBUG] org.hibernate.loader.Loader : total objects hydrated: 0
As you can see, hiberante correctly reads the data from the DB, but still a null is returned. I have no idea why. No information with WARN or higher priority is written about this in the logs. I get no stack trace.
While I'm certainly not a hibernate expert, I've spent a considerable amount of time trying to solve this, and currently I assume it's a hibernate bug (i.e. returning nulls without any warning is unexpected behavior). Perhaps it occurs when there are no fields outside the composite ID.