Spring ROO GWT 通过参考选择

发布于 2024-12-07 06:58:12 字数 1140 浏览 7 评论 0原文

我创建了一个包含以下实体的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

可爱咩 2024-12-14 06:58:12

我猜这不起作用的原因是 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)

尝蛊 2024-12-14 06:58:12

在 AppEngine 中,引用是通过被引用对象的 ID 进行的。所以
如果 ItemFacture 包含属性facture,则事件实际上存储为factureId。

所以写方法是这样的:

@SuppressWarnings("unchecked")
public static List<ItemFacture> findByFacture(Facture facture) {

    Query q = entityManager().createQuery("SELECT o FROM ItemFacture AS o WHERE o.factureId = :facture");
    q.setParameter("facture", facture.getId());

    return q.getResultList();
}

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:

@SuppressWarnings("unchecked")
public static List<ItemFacture> findByFacture(Facture facture) {

    Query q = entityManager().createQuery("SELECT o FROM ItemFacture AS o WHERE o.factureId = :facture");
    q.setParameter("facture", facture.getId());

    return q.getResultList();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文