1

I have the class Person:

@Entity
@Table(name = "person") 
@Inheritance(strategy= InheritanceType.JOINED)
@SequenceGenerator(name = "person_seq", sequenceName = "person_seq", initialValue = 1,  allocationSize = 1)
public class Person implements Serializable{ 
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "person_seq")
    @Column(name = "id")
    private long id;
} 

The class User:

@Entity
@Table(name = "user")
@PrimaryKeyJoinColumn(name = "id")
public class User extends Person{
    //some code
}

And the class Guest:

@Entity
@Table(name = "guest")
@PrimaryKeyJoinColumn(name = "id")
public class Guest extends Person{
    //some code
}

This way the inheritance works fine. The problem is: all the three tables has the column with the same name "id". I want the foreign key in the two last tables named "person_id".

If I change the column name on the childs, I get an "column name person_id not found in this Result Set" exception:

@PrimaryKeyJoinColumn(name = "person_id")

I also tried this way (still getting the same exception):

@PrimaryKeyJoinColumn(name = "person_id", referencedColumnName = "id")

Anyone know how to solve this problem?

Edit: Root cause:

org.postgresql.util.PSQLException: The column name person_id was not found in this ResultSet
org.postgresql.jdbc2.AbstractJdbc2ResultSet.findColumn(AbstractJdbc2ResultSet.java:2562)
org.postgresql.jdbc2.AbstractJdbc2ResultSet.getLong(AbstractJdbc2ResultSet.java:2431)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
org.hibernate.engine.jdbc.internal.proxy.AbstractResultSetProxyHandler.continueInvocation(AbstractResultSetProxyHandler.java:104)
org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
com.sun.proxy.$Proxy25.getLong(Unknown Source)
org.hibernate.id.IdentifierGeneratorHelper.get(IdentifierGeneratorHelper.java:149)
org.hibernate.id.IdentifierGeneratorHelper.getGeneratedIdentity(IdentifierGeneratorHelper.java:92)
org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:100)
org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:58)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2767)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3278)
org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:203)
org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:183)
org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:167)
org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:320)
org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:287)
org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:193)
org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:204)
org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:189)
org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:757)
org.hibernate.internal.SessionImpl.save(SessionImpl.java:749)
org.hibernate.internal.SessionImpl.save(SessionImpl.java:745)
br.com.hotel.upm.model.dao.hibernate.HibBaseDAO.create(HibBaseDAO.java:16)
br.com.hotel.action.LoginAction.execute(LoginAction.java:35)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
org.mentawai.core.InvocationChain.invoke(InvocationChain.java:315)
org.mentawai.filter.TransactionFilter.filter(TransactionFilter.java:169)
org.mentawai.core.InvocationChain.invoke(InvocationChain.java:147)
org.mentawai.filter.AjaxFilter.filter(AjaxFilter.java:25)
org.mentawai.core.InvocationChain.invoke(InvocationChain.java:147)
org.mentawai.filter.ValidatorFilter.filter(ValidatorFilter.java:184)
org.mentawai.filter.ValidationFilter.filter(ValidationFilter.java:137)
org.mentawai.core.InvocationChain.invoke(InvocationChain.java:147)
org.mentawai.filter.MentaContainerFilter.filter(MentaContainerFilter.java:46)
org.mentawai.core.InvocationChain.invoke(InvocationChain.java:147)
org.mentawai.filter.RedirectAfterLoginFilter.filter(RedirectAfterLoginFilter.java:54)
org.mentawai.core.InvocationChain.invoke(InvocationChain.java:147)
org.mentawai.filter.AuthenticationFilter.filter(AuthenticationFilter.java:172)
org.mentawai.core.InvocationChain.invoke(InvocationChain.java:147)
org.mentawai.core.Controller.invokeAction(Controller.java:1129)
org.mentawai.core.Controller.service(Controller.java:984)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

And the code where i get the exception:

Guest guest = new Guest("Rodrigo", "10341367630", "1231", "55 35131 131", date, "1123123", "cpf", "guest");
guestDAO.create(guest);

And the code in DAO:

public void create(Object objectRow) {
   session.save(objectRow);
   session.flush();
}

Thank's a lot.

4

0 回答 0