在处理基于JSF的工作时,我遇到了Hibernate继承问题。起初,我的目标是使用由两个具体类实现的接口,但由于映射接口不可行,我使用了由两个具体类扩展的抽象类。在代码方面:
@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) {
}
}
现在我有了第四个类(名为“Client”),它与AbstractEntity具有一对一的单向关系:
@Entity
public class Client implements Serializable {
private Long id;
private AbstractEntity holder;
...
@OneToOne
public SoggettoAstratto getHolder() {
return holder;
}
public void setHolder(SoggettoAstratto cliente) {
this.intestatario = cliente;
}
...
而个人是一个描述性的阶级,没有关系和财产,其中包括CodFis。 现在,如果我使用此条件进行查询:
Criteria crit = super.getSession().createCriteria(getPersistentClass());
crit.createCriteria("holder.billHolder")
.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.*
我得到了这个例外:
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)
我无法弄清楚问题是什么。谁做了?
提前致谢。 JLPicard
P.S。 属性名称是从我的语言翻译而来的,因此它们的平均值与英语不完全相同。