我有班级人物:
@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;
}
班级用户:
@Entity
@Table(name = "user")
@PrimaryKeyJoinColumn(name = "id")
public class User extends Person{
//some code
}
班级嘉宾:
@Entity
@Table(name = "guest")
@PrimaryKeyJoinColumn(name = "id")
public class Guest extends Person{
//some code
}
这样继承可以正常工作。问题是:所有三个表都具有相同名称“id”的列。我想在最后两个名为“person_id”的表中使用外键。
如果我更改了子项上的列名,我会收到“此结果集中未找到列名person_id”例外:
@PrimaryKeyJoinColumn(name = "person_id")
我也尝试过这种方式(仍然得到相同的例外):
@PrimaryKeyJoinColumn(name = "person_id", referencedColumnName = "id")
任何人都知道如何解决这个问题?
编辑:根本原因:
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)
我得到例外的代码:
Guest guest = new Guest("Rodrigo", "10341367630", "1231", "55 35131 131", date, "1123123", "cpf", "guest");
guestDAO.create(guest);
DAO中的代码:
public void create(Object objectRow) {
session.save(objectRow);
session.flush();
}
非常感谢。