saschwen wrote:
Hello,
I'm a newbie to hibernate and I have a question about how I would go about accomplishing something.
We have a content management system that uses oracle to store data. The basic table structure consists of 1 +n tables for then number of different content types. e.g. Article, Image, Collection, Link,...
The first table would have the columns id, assettype, and pubid. The pubid is a pointer to which site the asset belongs to. The assettype column tells me what table the asset data is in and the id column is the id of the asset i need to load from the table. for example if assettype is equal to Article then I would do a select from the article table with the id.
Is there a way to have hibernate do the work for this? There are approximately 10 - 15 different assettypes and it would be a lot of work and code if I had to first load the asset definition and then figure out what set of hibernate classes to use from there to load the asset data.
Thank you,
Steve.
look at the <joined-subclass> mapping in the docs. It would be something like this -
Code:
<hibernate-mapping>
<class name="BaseObject" table="BASE_TABLE">
<id name="id" column="ID" type="long">
<generator..../>
</id>
<many-to-one name="Site" column="pubid"/>
<joined-subclass name="Article" table="ARTICLES">
<key column="ARTICLE_ID"/> <!-- or whatever the column name is in the article table. -->
<!-- article specific columns go here'
</joined-subclass>
<joined-subclass name="Image" table="IMAGES" >
<key column="IMAGE_ID"/>
<!-- image specific columns go here'
</joined-subclass>
<joined-subclass name="Collection" table="COLLECTIONS" >
<key column="COLLECTION_ID"/>
<!-- collection specific columns go here'
</joined-subclass>
<joined-subclass name="Link" table="LINKS">
<key column="LINK_ID"/>
<!-- collection specific columns go here'
</joined-subclass>
....
....more subclasses...
....
</class>
</hibernate-mapping>