-->
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.  [ 9 posts ] 
Author Message
 Post subject: Is there something like @IdOverride?
PostPosted: Wed Jul 06, 2005 5:12 am 
Newbie

Joined: Wed Jul 06, 2005 5:08 am
Posts: 2
Is there an annotation that allows subclasses to override the id mapping of the base class? For example you have an abstract base class:

Code:
@EmbeddableSuperclass
public abstract class BaseEntity {
    private int id;

    @Id(generate = GeneratorType.NONE)
    public int getId() {
    }

    // Some logic using the id field.
}


And 2 concrete subclasses:

Code:
@Entity
public class NoAutonumbering extends BaseEntity {
}

@Entity
public class Autonumbering extends BaseEntity {
}


Most of the classes need to be mapped without sequences but some of them do use sequences in the database. I need a way to override the id mapping of the concrete Autonumbering class. I want it to be mapped using @Id(generate = GeneratorType.AUTO). I tried using the @AttributeOverride annotation but this does not seem to help me for @Id annotations.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 3:26 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No this is too evil IMO

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 4:16 pm 
Newbie

Joined: Wed Jul 06, 2005 5:08 am
Posts: 2
Ah too bad, but I don't get why this would be evil? All these classes already exist and use an int as their identifier. The only difference lies in the database where some ids are auto generated and some are not.

I just wanted to be sure that mapping this existing object model to the database is not possible using annotations while it is using plain xml files.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 4:54 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It is possible, just to map your superclass

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 11:32 am 
Newbie

Joined: Fri Mar 25, 2005 1:16 pm
Posts: 13
I also think this would be useful. Could you explain what you mean by it is possible? Do you mean via xml, or is there some annotations workaround?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 12:41 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
bunglebungle wrote:
Could you explain what you mean by it is possible? Do you mean via xml, or is there some annotations workaround?


You know what, I've no fucking idea, I was on crack I guess ;-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 11:05 am 
Newbie

Joined: Fri Mar 25, 2005 1:16 pm
Posts: 13
Can you explain a little more why this is evil? I can see not bothering to support it if the EJB spec doesn't call for it, but all other attributes can be overridden. It seems to me that just because I declare some class has an identifier doesn't mean I really care how it is stored or where it comes from. I don't mean to keep picking at this, it's just that this is currently causing me some irritation because I have some old XDoclet mappings that do exactly what was asked about and I can't convert them to annotations. Would it be easy to change this behavior if I wanted to patch it myself?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 2:38 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
What you can override so far are the column definitions.
I have a real bad feeling about the ability to override other parts. Mainly because the next step is to actually change the id property in the subclass that I don't want at all.

If you provide a patch I'll play with it and think it hard.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 05, 2008 6:18 am 
Newbie

Joined: Fri Mar 31, 2006 7:16 am
Posts: 2
bunglebungle wrote:
I also think this would be useful. Could you explain what you mean by it is possible? Do you mean via xml, or is there some annotations workaround?


I had the same need recently and achieved it by making my id @Transient in my abstract parent class and @Override it in my subclasses where i annotated it with @Id and @GeneratedValue.


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