-->
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.  [ 6 posts ] 
Author Message
 Post subject: Cannot instantiate abstract class or interface
PostPosted: Tue Nov 11, 2003 2:48 pm 
Newbie

Joined: Tue Nov 11, 2003 2:27 pm
Posts: 9
Greetings,

I'm trying to retrieve an instance by querying on its abstract base class. The base class doesn't have a table, but each implementing class has a separate one.

I've tried creating the data by hand and programmatically. Creating them programmatically results in entries in the DB, they just don't come out again when queried.

Here's the base class mapping:
<hibernate-mapping>
<class name="UserPreferences">
<id name="id" column="ID_UserPreferences" type="int">
<generator class="identity"/>
</id>
<property name="userId" column="User_ID" type="string"/>
</class>
</hibernate-mapping>

Implementing class mapping:
<hibernate-mapping>
<joined-subclass name="NTIRAInstallUserPrefs"
extends="UserPreferences"
table="UserPreferences" >
<key column="ID_UserPreferences"/>

<property name="decimalPlaces" column="DecimalPlaces" type="int"/>
</joined-subclass>
</hibernate-mapping>

The query "FROM UserPreferences AS up WHERE up.userId = ?"

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 11, 2003 3:00 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Hm... Subclass is joined-to-what? :)

I think, you must use <subclass> instead of <joined-subclass>.

Not sure, but doc says "It is perfectly acceptable for the named persistent class to be an interface. You would then declare implementing classes of that interface using the <subclass> element. "


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 11, 2003 4:00 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If Your abstract base class is not mapped to a table, then it must not be declared in the Hibernate mapping.
Default table is the unqualified class name (UserPreferences in your case for UserPreferences class).

Remove <class name="UserPreferences"> and map concrete classes with <class ...>

_________________
Emmanuel


Top
 Profile  
 
 Post subject: I think I figured it out
PostPosted: Tue Nov 11, 2003 6:58 pm 
Newbie

Joined: Tue Nov 11, 2003 2:27 pm
Posts: 9
It seems that the mapped class being abstract can only be used with the one table strategy. <joined-subclass> only works with a concrete base class to join off of.

However, I think I found the solution: I should have been using the fully qualified name in the query (I deleted the package names for readability and security, probably should have a place holder instead). That


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 11, 2003 7:07 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum I think you misunderstood me.

Since your abstract class has no table, Hibernate does not need to / must not have it in it's mapping files.

Code:
<class name="NTIRAInstallUserPrefs"
table="UserPreferences" >
...


No <class name="UserPreferences"> in your mapping files.

You can query user preferences by "from my.complete.qualifiedName.UserPreferences". It will return any mapped concrete classes that extends UserPreferences.

"from java.lang.Object" will return the entire database.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 19, 2006 8:36 am 
Beginner
Beginner

Joined: Mon Aug 02, 2004 7:28 am
Posts: 38
Is anyone still watching this issue?


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