-->
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: Issue with Hibernate Inheritance. Subclass using wrong seque
PostPosted: Thu Mar 17, 2011 3:36 pm 
Newbie

Joined: Thu Jul 17, 2008 1:24 pm
Posts: 9
Issue with Hibernate Inheritance. Subclass using wrong sequence.

My mappings are below.

Here is the base class for all classes. There is no table for this class. All subclasses user id as their PK.

Code:
@MappedSuperclass
public abstract class Model {
    private Long id;

    @Id
    @GeneratedValue(strategy=GenerationType.Sequence, generator="myGenerator")
    public Long getId() { return id; }
}


A class for Comments that has its own table, with columns for all the fields in Model

Code:
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@Table(name = "COMMENT")
@SequenceGenerator(name="myGenerator", sequenceName="COMMENT_SEQ", allocationSize=1)
public class Comment extends Model {
    //some data
}


A subclass of Comment that also has its own table, with columns for all the fields in Comment and Model

Code:
@Entity
@Table(name = "ORDER_COMMENT")
@SequenceGenerator(name="myGenerator", sequenceName="ORDER_COMMENT_SEQ", allocationSize=1)
public class OrderComment extends Model {
    //some data
}


This class has its own table and can have one to many order comments.

Code:
@Entity
@Table(name="ORDER")
@SequenceGenerator(name="myGenerator", sequenceName="ORDER_SEQ", allocationSize=1)
public class Order extends Model {
    private Set<OrderComment> = new HashSet<OrderComment>();

    @OneToMany
    @JoinColumn(name="ORDER_ID")
    public Set<OrderComment> getComments() { return comments; }
}


The issue is that when I add a new OrderComment to an Order, Hibernate selects the id from the sequence for Comment instead of the sequence for OrderComment.

Any ideas on why this is happening and what I can change to fix this issue? Or is there a better way to map this?


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.