2

I have created a parent class to have the fields or mappings common for all the entities in a single place.

But when the inheritance level is more than 1, hibernate throws the exception

MappingException: Repeated column in mapping for entity

The code sample is,

@MappedSuperclass
public abstract class BaseModel {

@Column(name="created_date")
private Date createdDate;

@Column(name = "modified_date")
private Date modifiedDate;

}

@MappedSuperclass
public class Order extends BaseModel {

@Column(name="due_date", nullable = true)
private Date dueDate;

}

@Entity 
public class Invoice extend Order {

}

Can someone please point out anything that I am doing wrong ?

dharshan
  • 733
  • 4
  • 11
  • 24
  • nothing wrong with having multiple levels of MappedSuperclass. Assuming you have an Id annotation somewhere then it is fine. No idea what you JPA provider message means. Try a different JPA provider – Neil Stockton Nov 10 '15 at 08:11
  • Thank so much neil. It works perfectly. Actually its a flaw in the code. – dharshan Nov 10 '15 at 08:16

2 Answers2

1

This works perfectly fine at my side just as a property in Invoice which will be the primary key.

I did this and it works perfectly created a table with 4 columns id,created_date date,modified_date,due_date

@Entity
public class Invoice extends Order {
    @Id
    String id;
}
1

The root cause for the problem is that an @Embeddable object inherited the BaseModel and its been used in the Invoice model. Hence the repeated column exception was thrown.

dharshan
  • 733
  • 4
  • 11
  • 24