-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Mapping Question/Advice
PostPosted: Fri Dec 26, 2003 12:10 pm 
Newbie

Joined: Wed Nov 05, 2003 9:10 am
Posts: 6
I'm relatively new to Hibernate. I can write and use some basic mappings, but I've got a question. The answer will help me relate better to Hibernate and hopefully learn how some others have addressed the same issue.

Let's say I wish to create a record of my music collection. The most natural breakdown for me was this:

Code:
public abstract class Recording{

     Set discs;
     Rating rating;
     Set recordingArtists;

     /* getters and setters */

}

public class Album extends Recording{

      String albumName;
      String releasedOnLabel;
      int yearReleased;

      /* getters and setters */
}

public class LiveShow extends Recording{

      Location recordedAt;
      Date recordedOn;
     
      /* getters and setters */

}


Since I don't think in Hibernate yet, my original thought was to place the ID column in Recording and write the mapping file with <class> and <joined-subclass>.

Hibernate complains with this scheme because it cannot instantiate a Recording. That seems natural enough to me; why should Hibernate expect to persist a non-instantiable class?

In this toy problem, I just removed the abstract and it worked fine, but there's a real project I'm working with now where this will not be an option. Is there any way to enforce non-instantiability of a class which will hold data that Hibernate will persist?

This mapping file will not exactly correspond to the above, but the issue is the same.

Code:
<hibernate-mapping>
<class name="com.jimvanfleet.jtunes.Recording" table="recording">
<id name="recordingID" type="string" unsaved-value="null">
<column name="recordingID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<many-to-one name="rating"/>
<set name="disc" cascade="all">
    <key column="recording"/>
    <one-to-many class="com.jimvanfleet.jtunes.Disc"/>
</set>

<joined-subclass name="com.jimvanfleet.jtunes.Album" table="album">
<key column="recordingID"/>
<property name="albumName"/>
<property name="releaseYear"/>
<property name="bmgNum"/>
<property name="amazID"/>
</joined-subclass>
<joined-subclass name="com.jimvanfleet.jtunes.LiveShow" table="liveshow">
<key column="recordingID"/>
<property name="showDate"/>
<property name="showLocation"/>
<property name="recSource"/>
<property name="showCity"/>
</joined-subclass>

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 29, 2003 6:43 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
can you post the code between begin and close of the session ?

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.