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: Hibernate OneToMany abstract Class override id
PostPosted: Tue Nov 22, 2011 4:38 pm 
Newbie

Joined: Fri Aug 18, 2006 6:47 am
Posts: 11
I'm using JPA 1.0 so I am limited in what I can do but I still think it should be possible to do the following however I cant get it working...

Code:
Table CustomerA
a_id


Table ProductB
a_id
b_id

Table ProductC
a_id
c_id

    @Entity
    @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
    public abstract class AbstractProduct {

        @Id
        @GeneratedValue....
       private Long id;
   
       private String name;

     @ManyToOne()
     JoinColumn(name="a_id")
     private CustomerA customerA;
   
    }



Now I want to create a subclass which can over ride the Id or create a composite Key based on the PK of Table A and the key of the derived table...

Code:
    @Entity
    @Table(name="ProductB")
    public class ProductB extends AbstractProduct {

        //@AttributeOverride(name="id", column=@Column(name="B_ID") //Can only be used     with MappedSuperClass and also Emmbedded Objects
        //@Id //cant override the ID Column so that cant go here
       //PrimaryKeycolumn join not what i want here
       private Long productB_id;
       
       private String productName;
    }

    @Entity
    @Table(name="CustomerA")
    public class CustomerA
    {
       @Id
       @GeneratedValue....
       @Column(name="a_id")
       private Long aId
       
        @OneToMany(mappedBy="customerA", cascade=CascadeType.ALL)
       private Set<AbstractProduct> product;
    }



So essentially CustomerA can contain many products, but it will always only be of either ProductB or ProductC. How can i override the Id in the subclass as you cant use attributeoverride and Entity, and if you use @Entity you must specify @Id whenever you specify an @Entity. I've read the jpa wiki and it looks rather complicated and ott to achieve this in JPA 1.0, but i'm wondering if I am missing something?


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.