Can hibernate resolve mapping across more than one table.
Here is example:
- Class Manufacturer, table MANUFACTURER
- Class Car, table CAR Class
- CarType, table CAR_TYPE
ORM Model
- MANUFACTURER one to many CAR (MANUFACTURER_ID_FK in table CAR)
- CAR many to one CAR_TYPE (CAR_TYPE_ID_FK in table CAR)
What I want is hibernate mapping that will resolve all CAR TYPES for given Manufacturer?
So if I wanted to get all cars I would write
<set name="cars" inverse="true" cascade="all,delete-orphan" lazy="false" >
<key property-ref="manufacturerIdFk">
<column name="MANUFACTURER_ID_FK " precision="22" scale="0" not-null="true"/>
</key>
<one-to-many class="foo.bar.Car" />
</set>
What I need is how to get car types for manufacturer?
<set name="carTypes" inverse="true" cascade="all,delete-orphan" lazy="false" >
???
</set>
Thank you and please don’t answer just get it from “cars” 🙂 Solution what I would like to implement should completely really on hibernate mapping to do “heavy lifting”. Thanks again.
You can map directly manufacturer.carTypes collection as a ManyToMany relationship based on the association table : CAR.
Here is an example (Annotations) :
In class Manufacturer