I'm using 3.1.3 (though 3.1.1 had the same problem) and am having a strange problem. This is a legacy DB and it would not be possible to change the structure. My mapping looks something like:
Code:
<class name="DBDrug" table="DRUG">
<composite-id>
<key-property name="facilityId" type="string">
<column name="FACILITY_ID" length="2" />
</key-property>
<key-property name="drugId" type="string">
<column name="DRUG_ID" length="12" />
</key-property>
</composite-id>
<property name="primaryName" type="string">
<column name="PRIMARY_NAME" length="50" />
</property>
...
<join table="DRUG_BARCODE">
<key>
<column name="FACILITY_ID" length="2" />
<column name="DRUG_ID" length="12" />
</key>
<property name="drugBarcode" type="string">
<column name="DRUG_BARCODE" length="40" />
</property>
...
</join>
</class>
and I select from the DRUG table with:
Code:
items = session.createQuery( "from DBDrug where drugId = ? and facilityId = ?" )
.setString(0, drugID)
.setString(1, facilityID).iterate();
When I look at the SQL that is generated there are two queries. The first returns just the primary key information and the second returns everything. The problem is that I can't get the data from the "everything" query - only the "key" query. To illustrate better.
The "key" query (cleaned up for formatting)
Code:
select dbdrug0_.FACILITY_ID as col_0_0_,
dbdrug0_.DRUG_ID as col_0_1_
from DRUG dbdrug0_
inner join DRUG_BARCODE dbdrug0_1_ on
dbdrug0_.FACILITY_ID=dbdrug0_1_.FACILITY_ID and
dbdrug0_.DRUG_ID=dbdrug0_1_.DRUG_ID
where dbdrug0_.DRUG_ID=? and dbdrug0_.FACILITY_ID=?
and the "everything" query (also cleaned up for formatting):
Code:
select dbdrug0_.FACILITY_ID as FACILITY1_18_0_,
dbdrug0_.DRUG_ID as DRUG2_18_0_,
dbdrug0_.PRIMARY_NAME as PRIMARY3_18_0_,
...
dbdrug0_1_.DRUG_BARCODE as DRUG3_19_0_,
from DRUG dbdrug0_
inner join DRUG_BARCODE dbdrug0_1_ on
dbdrug0_.FACILITY_ID=dbdrug0_1_.FACILITY_ID
and dbdrug0_.DRUG_ID=dbdrug0_1_.DRUG_ID
where dbdrug0_.FACILITY_ID=? and dbdrug0_.DRUG_ID=?
So Hibernate is doing the right thing eventually (running the second query by hand results in the expected data) but the result of the createQuery only has my facilityID and drugID set - nothing else.
Any thoughts as to where I'm going wrong?