Hibernate命名Query do do do do dy n extity java返回Select子句中的所有结果

发布于 2025-02-03 11:55:02 字数 1100 浏览 2 评论 0原文

我有一个称为产品的Java实体,其中我有一个具有多个关系的属性,另一个具有ManyTomany关系的属性以及具有本机Java类型(字符串,INT,Double)的其他属性,

@Entity
@Table(name="PRODUCT")
@NamedQueries(
@NamedQuery(
name="findProductByCategoryAndPictures"
query="Select distinct p from Product p inner join p.categories cat inner join p.picture pic  where p.id = :idProduct"
)
)
public class Product {
    private int id;
    private String name;
    private double price;
    private int quantity;
    @JsonIgnore
    @ManyToOne
    @JoinColumns({@JoinColumn(...),@JoinColumn(...)})
    private Category categories ;
    @JsonIgnore
    @ManyToMany
    @JoinTable(name="Picture",joinColumns={})
    private List<Picture> picture ;
    
    // Getters & Setters
}

我创建了一个命名查询产品对象与我的两个属性和许多tomany上的两个属性相连,但是我无法将我的对象的结果得到我的其他两个属性的值。我只能得到我的本地属性的值

,我拥有这个结果

{
 "id" :"1",
 "name" :"test",
 "price" :"10",
 "quantity" :"18",
}

,但是我想获得这个结果,

{
 "id" :"1",
 "name" :"test",
 "price" :"10",
 "quantity" :"18",
 "categories" :"..." ,
 "picture" :[] ,
}

该如何做到这一点?

I have a java entity called Product in which I have a property having a manytoone relation and another property having the manytomany relation as well as other properties having native java types (String,Int,double)

@Entity
@Table(name="PRODUCT")
@NamedQueries(
@NamedQuery(
name="findProductByCategoryAndPictures"
query="Select distinct p from Product p inner join p.categories cat inner join p.picture pic  where p.id = :idProduct"
)
)
public class Product {
    private int id;
    private String name;
    private double price;
    private int quantity;
    @JsonIgnore
    @ManyToOne
    @JoinColumns({@JoinColumn(...),@JoinColumn(...)})
    private Category categories ;
    @JsonIgnore
    @ManyToMany
    @JoinTable(name="Picture",joinColumns={})
    private List<Picture> picture ;
    
    // Getters & Setters
}

I created a named query in which I retrieve my Product object with joins on my two properties manytoone and manytomany, but I can't get in the result of my object the values of my two other properties. I only get the values of my native properties

I have juste this result

{
 "id" :"1",
 "name" :"test",
 "price" :"10",
 "quantity" :"18",
}

but i want to have this result

{
 "id" :"1",
 "name" :"test",
 "price" :"10",
 "quantity" :"18",
 "categories" :"..." ,
 "picture" :[] ,
}

How can i do this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

[浮城] 2025-02-10 11:55:02

我认为您的问题是@jsonignore。它将标记要忽略的属性或属性列表。在您的文件上删除@jsonignore

I think your problem is @JsonIgnore. It will mark a property or list of properties to be ignored. Remove @JsonIgnore over your fileds.

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