-->
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.  [ 7 posts ] 
Author Message
 Post subject: classnotfound exception while using subclass inheritance
PostPosted: Sun Jun 06, 2004 10:22 am 
Beginner
Beginner

Joined: Sun Jun 06, 2004 10:13 am
Posts: 20
i'm trying to persist several implementations of ProfilePermission interface in one table.. my map file looks like this:

<hibernate-mapping>
<class name="gov.ProfilePermission" table="profilepermission">
<id name="id" column="id">
<generator class="uuid.hex"/>
</id>
<discriminator column="permissiontype" type="string"/>
<property name="name"/>
<property name="action"/>
<subclass name="CountryPermission"/>
<subclass name="GroupPermission"/>
<subclass name="TheaterPermission"/>
</class>
</hibernate-mapping>

do i need a mapping file for each of the subtypes?

i'm getting:
net.sf.hibernate.MappingException: persistent class [CountryPermission] not found
....
Caused by: java.lang.ClassNotFoundException: CountryPermission

here's how i'm trying to persist:

Configuration cfg = new Configuration();
cfg.addClass(Profile.class);
cfg.addClass(ProfilePermission.class);
cfg.addClass(CountryPermission.class);
SessionFactory sessionFactory = cfg.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
session.save(profile);
transaction.commit();
session.close();


do i need to list each of the possible subtypes in the configuration?

thanks for any help.

G


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 06, 2004 11:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Specify the full classname in your mappings (including package) or us the package attribute of the hibernate-mapping element.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 06, 2004 1:42 pm 
Beginner
Beginner

Joined: Sun Jun 06, 2004 10:13 am
Posts: 20
ahh.. that was a dumb oversite!

ok, that got me to the next step, its still barfing, this time looking for a mapping file for the implemented class (CountryPermission.hbn.xml)..

is it the case that you must have a mapping file for EACH class?

i have read the docs and have searched this forum, but they don't explain in detail which files are required when using the subclass element.

thanks for any help
g


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 06, 2004 2:22 pm 
Beginner
Beginner

Joined: Sun Jun 06, 2004 10:13 am
Posts: 20
i'm not sure whats going on.

i have it working to the point of no error messages being thrown, but the subclasses are not being saved in the database.

if I add the subclass types to the configuration object, then hibernate barfs and says i need to provide a mapping file for those subclasses. if I only add the interface that the subclasses implement (ProfilePermission), then i get no errors, but the objects are not saved.

does this indicate anything in particular as the problem?

thanks
G


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 06, 2004 2:58 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
<subclass name="CountryPermission"/>
<subclass name="GroupPermission"/>
<subclass name="TheaterPermission"/>


where is discriminator-value attribute?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 07, 2004 9:41 am 
Beginner
Beginner

Joined: Sun Jun 06, 2004 10:13 am
Posts: 20
well, i didn't include the discriminator-value attributes because the docs say its optional, as the class name will be used if you don't provide one.. but ok, i did try it with that attribute and got the same problem.

i'm still not clear about what i should be putting in my Configuration object, when trying to save a collection of several different implementations of an interface? do i add each concreate class to the Configuration?

of course, i've tried doing this and hibernate complains that its missing the concrete class's mapping file.

so, i'd really like to know what is needed.. do you need a mapping file for each of the concrete classes for the interface or just a general one for the interface?

thanks for any help.

G


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 07, 2004 11:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
If you use Configuration.addClass(), yes, it is normal to have a separate document for each class. If you want something else - well, Configuration has plenty of JavaDoc.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.