dharshan
dharshan

Reputation: 763

@MappedSuperclass with more than 1 inheritance level throws Repeated column in mapping for entity exception

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 ?

Upvotes: 3

Views: 1892

Answers (2)

dharshan
dharshan

Reputation: 763

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.

Upvotes: 1

Biraj B Choudhury
Biraj B Choudhury

Reputation: 684

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;
}

Upvotes: 1

Related Questions