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: JPA single-table inheritance error in Hibernate 3.5
PostPosted: Fri Apr 23, 2010 6:14 pm 
Newbie

Joined: Tue Apr 20, 2010 8:48 am
Posts: 2
In Hibernate 3.5, inheritance using JPA single-table strategy seems to break. The same code was tested successfully using Hibernate 3.4.

The code is like this. The base entity class is Customer, which is mapped to table CUSTOMER. The column CUSTOMER_TYPE is the discriminator. When it is “C”, it is a regular Customer, When it is “P”, it is a PreferredCustomer.

@Entity
@Table(name = "CUSTOMER")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "CUSTOMER_TYPE",
discriminatorType = DiscriminatorType.STRING, length = 1)
@DiscriminatorValue(value = "C")
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.TABLE,
generator = "CUST_SEQ_GEN")
@Column(name = "CUSTOMER_ID_PK", updatable=false)
protected int customerId;

@Column(name = "CUSTOMER_TYPE", nullable=false)
@Enumerated(EnumType.STRING)
protected CustomerType customerType;

// .. …..
}

@Entity
@DiscriminatorValue(value = "P")
public class PreferredCustomer extends Customer {
// ...
}

With the mapping above, Hibernate 3.5 gives me the following error when reading the annotations during initialization:

org.hibernate.MappingException: Repeated column in mapping for entity: jpatest.entity.PreferredCustomer column: CUSTOMER_TYPE (should be mapped with insert="false" update="false")

Note that the customerType attribute is defined in the base entity Customer, and the derived entity PreferredCustomer should inherit it as is. This same code runs well with Hibernate 3.4 and EclipseLink.

I am wondering if this is a bug introduced in Hibernate 3.5?


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.