-->
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: Persist superclass when subclass not mapped
PostPosted: Wed Oct 12, 2005 10:57 am 
Beginner
Beginner

Joined: Mon Oct 11, 2004 12:30 pm
Posts: 21
Hibernate version:
3.0.5

Full stack trace of any exception that occurs:
Unknown entity: com.semagix.core.extraction.model.TransientEntity

Name and version of the database you are using:
hsqldb 1.8.0

I have what i think is probably an easy problem to fix, but I'm not sure of the best approach. I have a mapped class Entity in a library, and i've subclassed it with an unmapped class for some extra data. I'd like to be able to use them without worrying about the type (i.e. reference both as an Entity object ala instanceof), but when i persist, I only want to persist the Entity object, not any of the TransientEntity object's properties. I get the above stack trace when i try to saveOrUpdate the TransientEntity object, eventhough it's a subclass of an Entity. Is there a way to save it w/o mapping it, short of a deep copy?

Thanks,
Jason


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 11:55 am 
Beginner
Beginner

Joined: Wed Sep 21, 2005 11:52 am
Posts: 43
Some suggestions:

What if you just cast it to the superclass? Probably won't work, but worth a try.

Or, make a <subclass> mapping for TransientEntity that has nothing in it. It only inherits Entity mappings. Of course you would need to declare a discriminator in the Entity mapping and a discriminator value in TransientEntity mapping. This is the table-per-class-hierarchy strategy. Of course you would get TransientEntities when you retrieve from the database.

Or, if Entity is an abstract class why not just associate the mapping with TransientEntity. It doesn't matter that you don't map TransientEntity's variables. This is the table-per-concrete-class strategy. Once again you would be retrieving TransientEntities.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 12:43 pm 
Beginner
Beginner

Joined: Mon Oct 11, 2004 12:30 pm
Posts: 21
Entity is in a library i am importing. I want to manipulate it with some extra markup for processing, so i subclassed it with some additional unpersisted params. I'd prefer not to edit the mappings on the superclass to add a descriminator, so i tried this:

session.saveOrUpdate("com.semagix.ontology.model.Entity", obj);

where obj is a TransientEntity. Seems to work great!

Any of the hibernate team see a problem with this strategy?

Jason


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.