-->
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.  [ 2 posts ] 
Author Message
 Post subject: Overriding an annotated property (at the Java level)
PostPosted: Mon Jan 23, 2006 6:13 pm 
Newbie

Joined: Sun Jul 31, 2005 7:53 pm
Posts: 17
I am having difficultly overriding an annotated property 'at the Java level'. For example:

Code:

@MappedSuperclass
public abstract class NamedEntity
{
   @NotNull
   @Column( unique = true )
   public String getName()
   {
      return m_strName;
   }
}

@Entity
@Inheritance( strategy = InheritanceType.JOINED )
public abstract class Resource
   extends NamedEntity
{
   @UILabel( "Login" )
   public String getName()
   {
      return super.getName();
   }
}


Here, I have a base class 'NamedEntity' (which is an entity that has a name), and a subclass 'Resource' (which is later further subclassed into 'Staff', 'Client' etc). I need to override the 'Name' property so that I can add a new annotation that displays a slightly different label than 'Name' in the UI (@UILabel being one of my own annotations).

However, Hibernate Annotations always throws a 'duplicate property mapping' exception when I try this. The only way I have found to work around this is to further annotate the overriden property with @Transient, such that:

Code:
   @UILabel( "Login" )
   @Transient
   public String getName()
   {
      return super.getName();
   }


...but this seems very hacky. Is there a better way?

With the increasing prevelance of annotations used for both persistence and UI 'hints', I can see this kind of requirement becoming more and more common.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 23, 2006 8:24 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The problem is that there can be several rules when a property is overriden:
- read super method annotation
- avoid them
- merge both

EJB3 will not define any rule on it, but according to the non @Inherited use, the annotations should at best be ignored.
It's better not to put the property in the mapped superclass (either not do a mapped superclass or mark the super prioperty as transient)

Any other framework on the planet might choose different strategies regarding its reading strategy, so it cannot really be consistent

_________________
Emmanuel


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