Hi, I already used hibernate, but now I'm using Hibernate with JPA and having some problem with the Inheritance mapping. The classes are the following ones:
Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "Person")
public abstract class Person implements Serializable {
@Id
@Column(name = "idPerson", nullable = false)
private Long idPerson;
@Column(name = "inclusionDate", nullable = false)
@Temporal(TemporalType.DATE)
private Date inclusionDate;
//constructors, getters and setters omited
}
Here are the classes that inherit from class Person
Code:
@Entity
@PrimaryKeyJoinColumn(name = "idNormalPerson")
@Table(name = "NormalPerson")
public class NormalPerson extends Person implements Serializable {
@Column(name = "idNormalPerson", nullable = false)
private Long idNormalPerson;
@Column(name = "name", nullable = false)
private String name;
@Column(name = "sex", nullable = false)
private char sex;
@Column(name = "birthDate", nullable = false)
@Temporal(TemporalType.DATE)
private Date birthDate;
@Column(name = "email")
private String email;
//constructors, getters and setters omited
}
Code:
@Entity
@PrimaryKeyJoinColumn(name = "idBeneficiary")
@Table(name = "Beneficiary")
public abstract class Beneficiary extends NormalPerson implements Serializable {
@Column(name = "idBeneficiary", nullable = false)
private Long idBeneficiary;
@Column(name = "register", nullable = false)
private String register;
@Column(name = "vip", nullable = false)
private boolean vip;
//constructors, getters and setters omited
}
Finally
Code:
@Entity
@PrimaryKeyJoinColumn(name = "idHolder")
@Table(name = "Holder")
public class Holder extends Beneficiary implements Serializable {
@Column(name = "idHolder", nullable = false)
private Long idHolder;
@ManyToOne
@JoinColumn(name = "responsible")
private NormalPerson responsible;
//constructors, getters and setters omited
}
The classes here are simplified, but I'm getting the following mapping exception:
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.MappingException: Repeated column in mapping for entity: packageName.Holder column: idHolder (should be mapped with insert="false" update="false")
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:698)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at packageName.Test.main(AA.java:39)
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: packageName.Holder column: idHolder (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:605)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:627)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:645)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:420)
at org.hibernate.mapping.JoinedSubclass.validate(JoinedSubclass.java:40)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1026)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:691)
... 3 more