-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem with inheritance mapping
PostPosted: Mon Jan 15, 2007 9:18 am 
Newbie

Joined: Thu Jan 11, 2007 5:53 pm
Posts: 3
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 15, 2007 11:28 am 
Newbie

Joined: Thu Jan 11, 2007 11:27 am
Posts: 11
Im new to this but try to add following in @JoinColumn

Code:
insertable=false, updatable=false


Cheers!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 15, 2007 2:22 pm 
Newbie

Joined: Sun Jan 14, 2007 8:01 pm
Posts: 5
Does idNormalPerson and idBeneficiary map to the idPerson field in your database schema?
If so, you can omit those fields and simply inherit the idPerson field and use the getter/setter pair (or make it protected).

Also, if you're as consistent about naming as it seems, you may be able to omit the table and column name fields. I've thought it makes annotations more convenient.


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Mon Jan 15, 2007 4:19 pm 
Newbie

Joined: Thu Jan 11, 2007 5:53 pm
Posts: 3
I've just checked the database schema and made the following changes and it worked just fine

Code:
@Column(name = "idPessoaFisica", insertable = false, updatable = false)
    private Long idNormalPerson;


Thank you guys for the help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

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.