我正在尝试使用JPA 2.0来创建具有泛型关系的多态实体.应该有两个表,一个事件表和一个通知表.在这些表中是彼此相关的具体实体,如下所示:
Event <---------- Notification<X extends Event>
| |
LoginEvent <------ LoginNotification extends Notification<LoginEvent>
Run Code Online (Sandbox Code Playgroud)
从逻辑上讲,这应该可以在hibernate中实现,因为它可以在SQL中实现:
+----------+ +----------+
| Event | | Notif |
+----------+ +----------+
| | | Id |
| Id | <- | Evt_id |
| Type | <- | Type |
| ... | | ... |
+----------+ +----------+
Run Code Online (Sandbox Code Playgroud)
这就是我所拥有的:
@Entity
@Inheritance
public abstract class Event{
...
}
@Entity
public class LoginEvent extends Event{
...
}
@Entity
@Inheritance
public abstract class Notification<X extends Event>{
@ManyToOne(optional=false, targetEntity=Event.class)
@JoinColumn …Run Code Online (Sandbox Code Playgroud) 有没有人能够将LESS的精彩短缺语法与GWT UiBinder的令人敬畏的模块,重新因子友好和类型安全的CSS集成?
<ui:style with="com.lesscss.gwt">
.selector{
/* Can I haz LESS in here? */
}
</ui:style>
Run Code Online (Sandbox Code Playgroud)
当然,你可以使用LESS与GWT - 你只需要使用非编译的CSS.我希望我的CSS通过LESS编译器,然后是GWT编译器.
我试图在我正在使用JPA 2.0类型安全标准API编写的应用程序中使用子查询,Hibernate 3.6.1.Final作为我的提供者.我没有选择原始类型(Long,MyEntity等)的问题,但我想选择多个列.
这是一个完全合理的例子.忽略子查询的不必要使用 - 它只是说明了.
EntityManager em = getEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Tuple> cq = cb.createTupleQuery();
Subquery<Tuple> subQ = cq.subquery(Tuple.class);
Expression<Long> subqCount;
{
Root<MyEntity> root = subQ.from(MyEntity.class);
Path<MyEntity> filter = root.get(MyEntity.challenge);
subqCount = cb.count(root);
// How to select tuple?
Selection<Tuple> tuple = cb.tuple(filter, subqCount);
// !! Run-time exception here
Expression<Tuple> tupleExpr = (Expression<Tuple>) tuple;
// Not sure why I can't use multiSelect on a subQuery
// #select only accepts Expression<Tuple>
createSubQ.select(tupleExpr);
createSubQ.groupBy(filter);
}
cq.multiselect(subqCount);
Run Code Online (Sandbox Code Playgroud)
虽然编译器没有抱怨,但我仍然遇到运行时异常.
java.lang.ClassCastException: org.hibernate.ejb.criteria.expression.CompoundSelectionImpl cannot …Run Code Online (Sandbox Code Playgroud)