當我試圖查詢映射到Hibernate的實體時,我有一個JSF webapp拋出異常(見下文)。我究竟做錯了什麼?或者它是Hibernate中的一個Bug?我該如何解決這個問題?感謝您的幫助:)JPA 2.0/Hibernate:沒有發現超類型
下面是相關的類:
基類ShipmentUnit
一些子類:
@Entity
@Table(name = "tat_shipment_unit")
@Inheritance(strategy = SINGLE_TABLE)
@DiscriminatorColumn(name = "unit_type", discriminatorType = CHAR, length = 1)
@DiscriminatorValue("_")
public abstract class ShipmentUnit implements Serializable {
private Long id;
private List<ShipmentAction> actions;
@Id @GeneratedValue
public Long getId() { return id; } // and corresponding setter
@OneToMany(mappedBy = "unit")
@OrderBy("listIndex")
public List<ShipmentAction> getActions() { return actions; } // and setter
// hashCode, equals etc.
}
的ShipmentAction類:
@Entity
@Table(name = "tat_shipment_action")
@IdClass(ShipmentActionID.class)
public class ShipmentAction implements Serializable {
private ShipmentUnit unit;
private int listIndex;
@Id @ManyToOne @NotNull
public ShipmentUnit getUnit() { return unit; } // and setter
@Id @Column(name = "list_index", nullable = false)
public int getListIndex() { return listIndex; } // and setter
}
的ShipmentActionID
類對於getter和setter方法也具有相同簽名的unit
和listIndex
屬性。
現在,我想顯示一個h:dataTable
與LazyDataModel<ShipmentAction>
。數據模型的實現使用標準的API(1)計算;(2)查詢這些貨行動的實體,就像這樣:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Number> query = cb.createQuery(Number.class);
Root<ShipmentAction> root = query.from(ShipmentAction.class);
Predicate predicates = ...
int total = em.createQuery(
query.select(cb.count(root).where(predicates)
).getSingleResult().intValue();
在TypedQuery
應該em.createQuery(...)
異常正在被產生的力矩拋出:
[SEVERE] Error Rendering View[/tat/report/actions.xhtml]: java.lang.IllegalStateException: No supertype found
at org.hibernate.ejb.metamodel.AbstractIdentifiableType.requireSupertype(AbstractIdentifiableType.java:85)
at org.hibernate.ejb.metamodel.AbstractIdentifiableType.getIdType(AbstractIdentifiableType.java:173)
at org.hibernate.ejb.criteria.expression.function.AggregationFunction$COUNT.renderArguments(AggregationFunction.java:110)
at org.hibernate.ejb.criteria.expression.function.ParameterizedFunctionExpression.render(ParameterizedFunctionExpression.java:94)
at org.hibernate.ejb.criteria.expression.function.BasicFunctionExpression.renderProjection(BasicFunctionExpression.java:71)
at org.hibernate.ejb.criteria.QueryStructure.render(QueryStructure.java:250)
at org.hibernate.ejb.criteria.CriteriaQueryImpl.render(CriteriaQueryImpl.java:338)
at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:223)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:619)
我使用Hibernate的版本4.0.0.Final,AS 7
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.0.0.Final</version>
<scope>provided</scope>
</dependency>
我需要這個。但是,當我切換到嵌入式密鑰時,我還需要使用'@Query(「UserRel r select r from r.key.user1Id =?1」)註釋我的JpaRepository方法。 \t public Iterable findByUser1Id(long id1) ;' –
Spencer
2013-03-20 20:57:37