-->
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.  [ 5 posts ] 
Author Message
 Post subject: Possible to use parent class mapping for all the subclasses?
PostPosted: Fri Feb 22, 2008 8:11 pm 
Newbie

Joined: Mon Nov 05, 2007 4:44 pm
Posts: 9
My classes:
class A {
long id;
String abc;
}

class B extends A {
}

My mapping:
<hibernate-mapping>
<class name="A" table="A">
<!-- automatically incremental log ID -->
<id name="id" type="long" access="field">
<column name="ID" not-null="true"/>
<generator class="native"/>
</id>

<!-- basic properties -->
<property name="abc" type="string" not-null="false"/>
</class>
</hibernate-mapping>

Is it possible when I in my DAO when I call

getHibernateTemplate().save(new B());

it'll still use A's mapping instead of complaining that B is not mapped?

Regards,


Top
 Profile  
 
 Post subject: Re: Possible to use parent class mapping for all the subclas
PostPosted: Fri Feb 22, 2008 8:14 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
What's the point of having B then?


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 22, 2008 9:37 pm 
Newbie

Joined: Mon Nov 05, 2007 4:44 pm
Posts: 9
B can have other values but I don't want to store those. ie
class B extends A {
String value;
String value2;
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 23, 2008 1:56 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
bluefox wrote:
B can have other values but I don't want to store those. ie
class B extends A {
String value;
String value2;
}


I believe there is an overloading save method that accepts entity name and object. You could use that, but in general this is a poor design.



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 24, 2008 5:59 am 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
Another aproach would be to properly Map the subclasses of A using the single_table strategy.

It would have the benifit, that you'll get Bs out of Hibernate when selecting objects.

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


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