Hibernate命名Query do do do do dy n extity java返回Select子句中的所有结果
我有一个称为产品的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的问题是
@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.