Hibernate version:2.1
Mapping documents:needed
Code between sessionFactory.openSession() and session.close():needed
Full stack trace of any exception that occurs:n/a
Name and version of the database you are using:Pointbase Version: 4.4
Debug level Hibernate log excerpt:n/a
Can someone please give me a complete, simple example of a Hibernate mapping file, the JavaBeans classes generated and example usage for a set of classes, where one has a collection of the other and the one that is a collection has a composite id? I can't get mine to work and the Hibernate documentation is extremely lean on the composite-id section.
This is what I am trying to get to work, but I know it is wrong because I don't know how to use a composite-id. Each section is wrong as far as I know.
Thank you VERY much.:
Band bean's mapping:
<bag name="recordings" lazy="true" inverse="false"
cascade="none" order-by="BANDNAME">
<meta attribute="field-description">List of band's recordings.</meta>
<meta attribute="use-in-tostring">true</meta>
<key column="BANDNAME"/>
<one-to-many class="RecordingBean"/>
</bag>
Q: What is the correct way to use the composite-id from the RecordingBean below, in the mapping of the bag, above?
Recording bean mapping:
<composite-id>
<key-property name="bandname" type="string"
column="BANDNAME">
<meta attribute="field-description">Returns band's name.</meta>
<meta attribute="use-in-tostring">true</meta>
</key-property>
<key-property name="title" type="string" column="TITLE">
<meta attribute="field-description">Returns recording name.</meta>
<meta attribute="use-in-tostring">true</meta>
</key-property>
</composite-id>
This is how I try to load a recording:
RecordingBean rb = new RecordingBean(bandname, title);
try {
RecordingBean recording = (RecordingBean)
HibernateUtil.currentSession().load(RecordingBean.class, rb);
return recording;
} catch (Exception e) {
throw new PersistenceException("Could not retrieve.", e);
}
Q: How do you load a bean with a compsite id if you don't know or have its id?
A COMPLETE example would be a huge help. Thanks!
|