-->
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.  [ 3 posts ] 
Author Message
 Post subject: persisting sub classes
PostPosted: Tue May 22, 2007 3:28 pm 
Newbie

Joined: Sat Apr 14, 2007 7:23 am
Posts: 6
Hi,

I'm attempting to use a generic storage mechanism for a variety of objects in my system. I have defined a standard base object called Node which holds all the properties and methods that can be performed on them. Classes which extend Node are only permitted to add useful API calls on top of the functions offered by the Node. For example:

public class Node
{
public Node getChild(String name);
}

public class EmailAddress extends Node
{
public String getDomain()
{
return this.getChild("domain");
}
}

When I come to save this, I am casting EmailAddress as Node and passing it into the save() method of the session. This is throwing an error as follows:

org.hibernate.MappingException: Unknown entity: classes.EmailAddress

Can what I want to do be done with Hibernate, or will it require a mapping document be supplied for every unique class, even if they all extend from a single mapped class?

Cheers,

Richard


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 22, 2007 11:46 pm 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
You have a few options.

Look at this.

http://www.hibernate.org/hib_docs/v3/re ... nheritance

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 23, 2007 2:14 am 
Newbie

Joined: Sat Apr 14, 2007 7:23 am
Posts: 6
Hi Budyanto,

Thanks for the link. I had a look at this page yesterday, and it didn't seem to quite address the problem, unfortunately. All the strategies require that the hibernate configuration know about the subclasses. The trick of what I'm trying to do is exactly the opposite: Hibernate should only know about the Node class, and all extensions to it are API sugar, and nothing whatsoever to do with storage (so, for example, the EmailAddress class is not permitted to add new information to be stored which couldn't have been represented by a Node class and a caller which understood the structure of an email address). For this reason, I explicitly don't want hibernate to know about the classes because that will limit the extensibility of the code.

I got around this yesterday evening by turning EmailAddress into a Decorator for the Node class instead, with a getter and setter for the MetadataNode. This is frustrating because although I get all of the functionality I wanted from the above strategy, and hibernate can deal with it, since we only use a pure Node class for storage and retrieval, I don't get the polymorphism that I wanted out of the object tree.

public class EmailAddress
{
private Node node;

public String getDomain()
{
node.getChild("domain");
}
}

Cheers,

Richard


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