-->
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.  [ 1 post ] 
Author Message
 Post subject: Extend a class without implicit inheritance?
PostPosted: Wed Jan 12, 2011 3:12 pm 
Newbie

Joined: Wed Jan 12, 2011 2:55 pm
Posts: 1
Here is the scenario. I have Class A and Class B. B extends A in Java. Each has it's own table with it's own set of columns. Example:
Code:
@Entity
@Table(name="MyA")
public Class A
{
   private firstName;

   private lastName;

   public String getFirstName()
   {...}

   public void setFirstName(...)
   {...}

   public String getLastName()
   {...}

   public void setLastName(...)
   {...}
}

@Entity
@Table(name="MyB")
public Class B extends A
{
   private middleName;

   public String getMiddleName()
   {...}

   public void setMiddleName(...)
   {...}
}


Table MyA has columns [id,firstName,lastName], Table MyB has columns [id,firstName,lastName,middleName]

Initially, without a inheritance strategy, it wants to look in the same table for both. I decided to use a inheritance strategy of TABLE_PER_CLASS, but this causes problems when I try to get a count of Class B.

Example
select count(myB) from B myB; --returns the count of the union of myA and myB.

I really just want to treat class myB has it's own entity. I figure one solution is to create a MappedSuperClass with the common columns, then extend it in the other classes. I was just wondering if there is a shortcut. Can I extend a class, but tell hibernate not to use an inheritance strategy? Hope this isn't a stupid question! Thanks in advance for your help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.