Spring ROO GWT 通过参考选择
我创建了一个包含以下实体的 GWT Spring ROO 项目:Facture 和 ItemFacture。
ItemFacture 包含对 Facture 的引用。
@RooJavaBean
@RooToString
public class ItemFacture {
@ManyToOne
private Facture facture;
...
这是 Facture 的代码:
@RooJavaBean
@RooToString
@RooEntity
public class Facture {
private String nom;
private String type;
}
一切都很顺利,直到我想创建一个自定义查找器来选择包含特定 Facture 的所有 ItemFacture:
@SuppressWarnings("unchecked")
public static List<ItemFacture> findByFacture(Facture facture) {
Query q = entityManager().createQuery("SELECT o FROM ItemFacture AS o WHERE o.facture = :facture");
q.setParameter("facture", facture);
return q.getResultList();
}
当我尝试执行此查找器时,它给出了以下错误:
服务器错误:com.test.ItemFacture 中不存在字段“facture”或不持久;嵌套异常是 javax.persistence.PersistenceException:字段“facture”在 com.test.ItemFacture 中不存在或不是持久的
我创建了一些自定义查找器,除了这个之外,它们中的每一个都工作得很好。
我尝试将 @Persistent 添加到字段并将 @PersistenceCapable(identityType = IdentityType.APPLICATION) 添加到 Facture,但它仍然不起作用。
有人知道是什么问题吗?
I created a GWT Spring ROO project with the following entities: Facture and ItemFacture.
ItemFacture contains a reference to a Facture.
@RooJavaBean
@RooToString
public class ItemFacture {
@ManyToOne
private Facture facture;
...
This is the code for Facture :
@RooJavaBean
@RooToString
@RooEntity
public class Facture {
private String nom;
private String type;
}
and everything went fine until I wanted to create a custom finder that selects all the ItemFactures that contains a specific Facture :
@SuppressWarnings("unchecked")
public static List<ItemFacture> findByFacture(Facture facture) {
Query q = entityManager().createQuery("SELECT o FROM ItemFacture AS o WHERE o.facture = :facture");
q.setParameter("facture", facture);
return q.getResultList();
}
When I try to execute this finder, it gives me this error:
Server Error: Field "facture" does not exist in com.test.ItemFacture or is not persistent; nested exception is javax.persistence.PersistenceException: Field "facture" does not exist in com.test.ItemFacture or is not persistent
I created a few custom finders and every one of them worked just fine except this one.
I tried adding @Persistent to the field and @PersistenceCapable(identityType = IdentityType.APPLICATION) to Facture but it still doesn't work.
Anyone know what is the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜这不起作用的原因是 ItemFacture 类不是 @Entity 所以 JPA 不知道这个字段存在。使用 @RooEntity 注释 ItemFacture 类 roo 会生成一个 ItemFactures_Roo_Entity.aj (默认情况下,STS 在包资源管理器中隐藏这些文件),它将 ItemFacture 类上的 @Entity 注释与其他一些内容连接在一起,使其成为 ActiveRecord (http:// /martinfowler.com/eaaCatalog/activeRecord.html)
i guess the reason why this doesn't work is that the ItemFacture class is not an @Entity so JPA has no idea this field exists. with annotating the ItemFacture class with @RooEntity roo generates a ItemFactures_Roo_Entity.aj (STS hides these files in the package explorer by default) which wires the @Entity annotation on your ItemFacture-class together with some other stuff making it an ActiveRecord (http://martinfowler.com/eaaCatalog/activeRecord.html)
在 AppEngine 中,引用是通过被引用对象的 ID 进行的。所以
如果 ItemFacture 包含属性facture,则事件实际上存储为factureId。
所以写方法是这样的:
In AppEngine, references are made with the ID of the referenced object. So
event if ItemFacture contain and attribute facture, it's actually stored as factureId.
So the method to write is this one: