-->
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: inheritence and column names
PostPosted: Mon Nov 28, 2005 5:22 pm 
Newbie

Joined: Wed Sep 22, 2004 10:25 pm
Posts: 9
Location: Rochester, NY USA
If I have a base class with a property and I use an annotation to give it a column name, it seems I'm stuck with that column name for all subclasses.

With hbm.xml mapping files, I can have a base class with, say, set/getId():Long, but then map the column name separately per subclass so I can have foo_id and bar_id (same java property but different db column names).

How would I do this in ejb3? Define the id property as @Transient in the base class, then override it each the subclass with @Id and @Column? I know I could just try it, but I want to know (if it works), is it an accepted path? What do other people do?

Much thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 5:39 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
@PrimaryJoinColumn for JOINED strategy
this is not possible for table per class

_________________
Emmanuel


Top
 Profile  
 
 Post subject: EJB and @Column override in subclasses
PostPosted: Fri Dec 09, 2005 6:20 pm 
Newbie

Joined: Fri Dec 09, 2005 6:15 pm
Posts: 2
I've tried overriding a @Column in a subclass, and it doesn't work. My code appears as follows:

Code:
@Entity public abstract class AuditedEntity {

   @Id(generate = GeneratorType.AUTO)
   @Basic(optional = false)
   @Column(name = "Id", nullable = false)
   public abstract Long getId();

   public abstract void setId(Long id);
}


The concrete class looks like this:

Code:
@Entity public class UserProfile {

   @Basic(optional = false)
   @Column(name = "UserId", nullable = false)
   public Long getId() { ... }

   public void setId(Long id)  { ... }
}


This code deploys fine, however it seems that Hibernate ignores the @Column annotation in the base class. Should this approach work? I haven't seen any text in the EJB3 spec. to the contrary. Is this just a limitation of Hibernate?


Top
 Profile  
 
 Post subject: Superclass should not override relational mapping
PostPosted: Fri Dec 09, 2005 6:27 pm 
Newbie

Joined: Fri Dec 09, 2005 6:15 pm
Posts: 2
Further reading of the EJB3 spec found this:
Quote:

Entity subclasses may override the property accessor methods. However, portable applications must not
override the object/relational mapping metadata that applies to the persistent fields or properties of
entity superclasses.


So it looks like the EJB3 spec says this approach is a bad idea. Too bad.


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.