The mapping below describes a model where I'd like to have certain items (in this case, a mechanical Jack) assigned to a Job. The relationship is established using the "reservedJobId" field in the "jacks" table. If it is assigned to no job, then the value is NULL.
Everything works fine when the table contains no NULL values for reservedJobId. However, when any of the rows contain a NULL value for that column, Hibernate starts acting strange. When I request a list (code shown below), it will return a List of the correct size, but only the first object will be valid. The rest will be null entries. What's stranger is when I do a consecutive request for the same list in the same section, the first TWO entries will be valid. This pattern of behavior repeats itself for every consecutive request (i.e., on the third request, the first three entries will be valid, on the fourth four, etc).
I've verified that Hibernate is generating the correct SQL.
Anyone have any idea what could be going on? Thanks in advance
Hibernate version: 2.1.5
Mapping documents:
Code:
<class name="Job" table="jobs" >
<id name="id" type="long" column="id">
<generator class="native" />
</id>
<property name="proposalName" />
<property name="description" />
</class>
<class name="Jack" table="jacks">
<id name="id" type="long">
<generator class="native" />
</id>
<many-to-one name="model" class="Jack$JackModel" cascade="none" column="modelId" />
<many-to-one name="reservedJob"
class="Job"
cascade="all"
column="reservedJobId"
not-null="false"/>
</class>
Code between sessionFactory.openSession() and session.close():Code:
List l = s.createQuery("from com.vbar.vt.model.Jack").list();
Name and version of the database you are using: MySQL 4.1.x
The generated SQL (show_sql=true): Code:
select jack0_.id as id, jack0_.modelId as modelId, jack0_.reservedJobId as reserved3_ from jacks jack0_
[/code]