-->
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.  [ 6 posts ] 
Author Message
 Post subject: MappedSuperclass on base class with Id
PostPosted: Thu Nov 09, 2006 6:41 pm 
Newbie

Joined: Tue Oct 24, 2006 9:21 pm
Posts: 12
Can you have a @MappedSuperclass annotation on a baseClass that has an Id property and the super classes will just override the getId() method to have the @Id annotation?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 6:12 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I do not think it works, I don't understand why it is useful either :-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 6:02 pm 
Newbie

Joined: Tue Oct 24, 2006 9:21 pm
Posts: 12
The reason why i wantedt this is because I want to define an abstract PersistableClass that has a Long getId() and all my persistable classes subclass this base class.

I have managed to get it working but I had to put @MappedSuperClass on the abstract class and marked the getId() as @Transient. On the subclasses they override the getId() method and has the @Id annotation


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 5:00 pm 
Beginner
Beginner

Joined: Fri Oct 07, 2005 5:35 am
Posts: 38
Location: France
If your Id is a Long, just add the property with its setter/getter and annotations in you base class (annotated with MappedSuperClass). In your subclass no nedd to take care about the Id anymore.

I used it, and it works fine.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 23, 2006 1:09 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I never unerstood the benefit of a PersistentClass superclass, if you really need such things, use an Interface.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 23, 2006 1:44 pm 
Beginner
Beginner

Joined: Fri Oct 07, 2005 5:35 am
Posts: 38
Location: France
I have an interface with 2 methods getId and getVersion.

In most of my classes, id is generated and version is just a long annotated with version. In thta case, the superclass is just a convenient way not to rewritte in all my classes the version and the id.

Moreover, most of my persistent entites will never goes in a transient map or collections. In my superclass I wrotte a equals and hashcode based on the value of the id (risks of doing such impl is discussed on the wiki).


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