-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mapping Base class
PostPosted: Tue May 13, 2008 5:09 am 
Newbie

Joined: Tue May 13, 2008 5:00 am
Posts: 2
I wrote code:
Code:
class BaseClass
{
// some properties
}

and mapping for BaseClass

when
Code:
class Impl1 : BaseClass
{
// some implementation
}


Code:
class Impl2 : BaseClass
{
// some implementation
}


And save it:
Code:
BaseClass bc = new Impl1(...);
session.Save(bc);


And catch exception "Unknown entity class: Impl1".
Why is this happening?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 13, 2008 5:22 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Since you save an Impl1 instance, you also need a mapping for that type. Even if you only want to store the BaseClass part of Impl1.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 13, 2008 5:32 am 
Newbie

Joined: Tue May 13, 2008 5:00 am
Posts: 2
wolli wrote:
Since you save an Impl1 instance, you also need a mapping for that type. Even if you only want to store the BaseClass part of Impl1.

I want to store only BaseClass, Impl1 this is only the implementation.
I tried also:
Code:
session.Save((BaseClass)bc);

It did not work.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 13, 2008 7:04 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
As I said, you need mappings for your implementation types. They can be empty, but you need them. Otherwise hibernate has no way to find out, what object it has to instantiate if a "BaseClass" is loaded, Impl1 or Impl2 !

If you want to separate the data from the logic/implementation, you can map the data as a component in both implementing classes.

_________________
--Wolfgang


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