hi,
We have tables similar to Payment{id, col1, col2} (Table1.id is primary key; auto increment one)
PaymentAmount{payment_id,transaction_status, col1, col2... } (PaymentAmount.payment_id references Payment.id; [id, status] together form the pk for PaymentAmount;
Now, I have the hibernate mappings auto generated by eclipse plugin;
Code:
Payment{
Integer id;
...
Set<PaymentAmountId> paymentAmount;
.. setters and getters
}
PaymentAmount{
public class PaymentAmount implements java.io.Serializable {
private PaymentAmountId id;
private Payment envPayment;
.. setters and getters;
}
When using criteria queries, I use the below code:
Code:
List list = s.createCriteria(Payment.class)
.add( Restrictions.eq("id", 1) )
.setFetchMode("paymentAmounts", FetchMode.JOIN)
.list();
What i see is Set<PaymentAmount> is always empty; THe sql stmt generated when run in Toad regturns a valid tuple containing payment and paymentAmount;
the HBM files are as follows:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 19 Jun, 2011 9:27:06 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.company.Payment" table="payment" catalog="cashier">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity" />
</id>
<many-to-one name="BankDetails" class="com.company.BankDetails" fetch="select">
<column name="bank_details" />
</many-to-one>
...
...
<bag name="PaymentAmounts" table="payment_amount" inverse="true" lazy="true" fetch="select" cascade="all" >
<key>
<column name="payment_id" not-null="true" />
</key>
<one-to-many class="com.company.PaymentAmount" />
</bag>
</class>
</hibernate-mapping>
and
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 19 Jun, 2011 9:27:06 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.company.PaymentAmount" table="payment_amount" catalog="cashier">
<composite-id name="id" class="com.company.PaymentAmountId">
<key-property name="paymentId" type="int">
<column name="payment_id" />
</key-property>
...
...
<key-property name="transactionType" type="string">
<column name="transaction_type" length="7" />
</key-property>
...
...
</composite-id>
<many-to-one name="Payment" class="com.company.Payment" update="false" insert="false" fetch="select">
<column name="payment_id" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>
Any ideas where i m doing mistake? Any help?
-regards,
ravi