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: One-to-one association with a joined-subclass inheritance
PostPosted: Fri Nov 12, 2010 4:49 pm 
Newbie

Joined: Fri Nov 12, 2010 4:44 pm
Posts: 1
Hello to everyone.
I'm stucked on a Hibernate inheritance problem while working on a JSF-based. At first, I was oriented to use a interface implemented by two concrete classes but since mapping interfaces is not possible I used an abstract class extended by the two concrete classes. In terms of code:

Code:
   @Entity
    @Inheritance(strategy=InheritanceType.JOINED)
    public abstract class AbstractEntity implements Serializable {
   
        protected Long id;
   
        @Id
        @GeneratedValue(strategy=GenerationType.TABLE)
        public Long getId() {
            return id;
        }
   
        public void setId(Long id) {
            this.id = id;
        }
    }

    @Entity
    @PrimaryKeyJoinColumn(name="id_company")
    public class Company extends AbstractEntity {
   
       private Individal signer;
        private Individuo billHolder;
        private String partIva;
   
        @OneToOne
        public Individual getSigner() {
            return signer;
        }
   
        public void setSigner(Individual signer) {
            this.signer = signer;
        }
   
        @OneToOne
        public Individual getBillHolder() {
            return billHolder;
        }
   
        public void setBillHolder(Individual billHolder) {
            this.billHolder = billHolder;
        }
   
        public String getPartIva() {
            return partIva;
        }
   
        public void setPartIva(String partIva) {
            this.partIva = partIva;
        }
    }

    @Entity
    @PrimaryKeyJoinColumn(name="id_private")
    public class Private extends AbstractEntity {
   
       private Individual billHolder;
   
        @OneToOne
        public Individual getBillHolder() {
            return billHolder;
        }
   
        public void setBillHolder(Individual billHolder) {
            this.billHolder = billHolder;
        }
   
        @OneToOne
        public Individual getSigner() {
            return billHolder;
        }
   
        public void setSigner(Individual signer) {
        }
    }


Now I have a fourth class (named "Client") that has a One-to-One monodirectional relation with AbstractEntity:

Code:
@Entity
    public class Client implements Serializable {
   
        private Long id;
        private AbstractEntity holder;

        ...

        @OneToOne
        public AbstractEntity getHolder() {
            return holder;
        }
   
        public void setHolder(AbstractEntity client) {
            this.holder = client;
        }

       ...


And Individual is a descriptive class without relations and a property, among other, called CodFis.
Now if I query using this criteria:

Code:
Criteria crit = super.getSession().createCriteria(getPersistentClass());
    crit.createCriteria("intestatario.intestatarioFatt")
       .add(Restrictions.eq("codFis", codFis));
    List risultati = crit.list();
   
    * NOTE: the code is part of a DAO. The getPersistentClass returns a Client.class, and it works perfectly with other methods in this DAO.*


I get this exception:

Code:
org.postgresql.util.PSQLException: ERROR: table name "individual1_" specified more than once
       at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2062)
       at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1795)
       at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
       at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479)
       at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:367)
       at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
       at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
       at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)

I can't figured out what's the problem. Anyone who does?

Thanks in advance.
JLPicard

P.S.
The property names are translated from my language, so their mean doesn't match exactly in english.


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.