我遇到错误,只能假设查询有问题。我正在尝试使用JPQL中的“新”关键字来初始化类,如下所示:
@Query("SELECT NEW com.htd.domain.ShopOrder(po.id, po.po_number, "
+ "po.due_date, po_part.id, po_part.part_quantity, "
+ "part.id, part.part_number, part.part_description "
+ "part.plasma_hrs_per_part, part.grind_hrs_per_part, "
+ "part.mill_hrs_per_part, part.brakepress_hrs_per_part) "
+ "FROM Po po "
+ "LEFT JOIN po.partList po_part "
+ "LEFT JOIN po_part.part")
List<ShopOrder> getShopOrder();
po_part.java
@Entity
@Table(name = "T_PO_PART")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Po_part implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "part_quantity")
private Integer part_quantity;
@ManyToOne
private Part part;
@ManyToOne
private Po po;
Po.java
@OneToMany(mappedBy="po",targetEntity=Po_part.class)
private List<Po_part> poList;
part.java
@OneToMany(mappedBy="part",targetEntity=Po_part.class)
private List<Po_part> partList;
我的数据库看起来像:
ShopOrder.java
public ShopOrder(int po_id, long po_number, Date po_due_date,
long po_part_id, int part_quantity, int part_id, int
part_number, String part_decription, long plasma_hrs, long gring_hours,
long mill_hrs, long breakpress_hrs) {
错误:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: part near line 1, column 155 [SELECT NEW com.htd.domain.ShopOrder(po.id, po.po_number, po.due_date, po_part.id, po_part.part_quantity, part.id, part.part_number, part.part_description part.plasma_hrs_per_part, part.grind_hrs_per_part, part.mill_hrs_per_part, part.brakepress_hrs_per_part) FROM com.htd.domain.Po po LEFT JOIN po.partList po_part LEFT JOIN po_part.part]
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:91) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:109) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:304) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:203) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1800) ~[hibernate-core-4.3.6.Final.jar:4.3.6.Final]
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:328) ~[hibernate-entitymanager-4.3.6.Final.jar:4.3.6.Final]
... 72 common frames omitted
------------更新--------------------
@Query("SELECT NEW com.htd.domain.ShopOrder(po.id, po.po_number, "
+ "po.due_date, po_part.id, po_part.part_quantity, "
+ "part.id, part.part_number, part.part_description, "
+ "part.plasma_hrs_per_part, part.grind_hrs_per_part, "
+ "part.mill_hrs_per_part, part.brakepress_hrs_per_part) "
+ "FROM Po po "
+ "LEFT JOIN po.partList po_part "
+ "LEFT JOIN po_part.part part "
+ "LEFT JOIN po_part.part")
仍然给我以下错误:
Invalid path: 'part.id' [SELECT NEW com.htd.domain.ShopOrder(po.id,
po.po_numbe
--------------更新----------------------
Part.java
@OneToMany(mappedBy="part",targetEntity=Po_part.class)
private List<Po_part> partList;
Po.java
@OneToMany(mappedBy="po",targetEntity=Po_part.class)
private List<Po_part> partList;
public List<Po_part> getPartList() {
return partList;
}
po_part.java
@ManyToOne
private Part part;
@ManyToOne
private Po po;
ShopOrder
public ShopOrder(int po_id, long po_number, Date po_due_date,
long po_part_id, int part_quantity, int part_id, int part_number,
String part_decription, long plasma_hrs, long grind_hours,
long mill_hrs, long breakpress_hrs) {
询问
@Query("SELECT NEW ShopOrder(po.id, po.po_number, "
+ "po.due_date, po_part.id, po_part.part_quantity, "
+ "part.id, part.part_number, part.part_description, "
+ "part.plasma_hrs_per_part, part.grind_hrs_per_part, "
+ "part.mill_hrs_per_part, part.brakepress_hrs_per_part) "
+ "FROM Po po "
+ "LEFT JOIN po.partList po_part "
+ "LEFT JOIN po_part.part part"
+ "LEFT JOIN po_part.part")
List<ShopOrder> getShopOrder();
在您的更新中,您传递的对象与传递变量一样。错了吗我仍然遇到相同的错误:
Invalid path: 'part.id' [SELECT NEW
-----------更新--------------
Po.java
public class Po implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "po_number")
private String po_number;
@Column(name = "sales_order_number")
private String sales_order_number;
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
@JsonSerialize(using = CustomLocalDateSerializer.class)
@JsonDeserialize(using = ISO8601LocalDateDeserializer.class)
@Column(name = "due_date")
private LocalDate due_date;
@Column(name = "status")
private String status;
@Column(name = "total_sale", precision=10, scale=2)
private BigDecimal total_sale;
@ManyToOne
@JoinColumn(name = "customer_id", referencedColumnName = "id")
private Customer customer;
@OneToMany(mappedBy="po",targetEntity=Po_part.class)
private List<Po_part> partList;
part.java
@Entity
@Table(name = "T_PART")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Part implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "part_number")
private String part_number;
@Column(name = "part_description")
private String part_description;
@Column(name = "plasma_hrs_per_part", precision=12, scale=4)
private BigDecimal plasma_hrs_per_part;
@Column(name = "laser_hrs_per_part", precision=12, scale=4)
private BigDecimal laser_hrs_per_part;
@Column(name = "grind_hrs_per_part", precision=12, scale=4)
private BigDecimal grind_hrs_per_part;
@Column(name = "mill_hrs_per_part", precision=12, scale=4)
private BigDecimal mill_hrs_per_part;
@Column(name = "brakepress_hrs_per_part", precision=12, scale=4)
private BigDecimal brakepress_hrs_per_part;
@Column(name = "lb_per_part", precision=12, scale=4)
private BigDecimal lb_per_part;
@Column(name = "inventory_count")
private Integer inventory_count;
@ManyToMany
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JoinTable(name = "T_PART_MATERIAL",
joinColumns = @JoinColumn(name="parts_id", referencedColumnName="ID"),
inverseJoinColumns = @JoinColumn(name="materials_id", referencedColumnName="ID"))
private Set<Material> materials = new HashSet<>();
@OneToMany(mappedBy="part",targetEntity=Po_part.class)
private List<Po_part> partList;
public List<Po_part> getPartList() {
return partList;
}
流行艺术
public class Po_part implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "part_quantity")
private Integer part_quantity;
@ManyToOne
private Part part;
@ManyToOne
private Po po;
ShopOrder
public ShopOrder(int po_id, long po_number, Date po_due_date,
long po_part_id, int part_quantity, int part_id, int part_number,
String part_decription, long plasma_hrs, long grind_hours,
long mill_hrs, long breakpress_hrs) {
最佳答案
part.part_description part.plasma_hrs_per_part缺少一个冒号
-更新-
我做了一个在服务器上运行的简单示例。
@Entity
public class Po extends UUIDIdentified {
private static final long serialVersionUID = 1L;
@OneToMany(mappedBy = "po", targetEntity = PoPart.class)
List<PoPart> poParts;
public List<PoPart> getPoParts() {
return poParts;
}
public void setPoParts(List<PoPart> poParts) {
this.poParts = poParts;
}
}
和
@Entity
public class Part extends UUIDIdentified {
private static final long serialVersionUID = 1L;
@OneToMany(mappedBy = "part", targetEntity = PoPart.class)
List<PoPart> poParts;
public List<PoPart> getPoParts() {
return poParts;
}
public void setPoParts(List<PoPart> poParts) {
this.poParts = poParts;
}
}
和
@Entity
public class PoPart extends UUIDIdentified {
private static final long serialVersionUID = 1L;
@ManyToOne
Po po;
@ManyToOne
Part part;
public Po getPo() {
return po;
}
public void setPo(Po po) {
this.po = po;
}
}
和
public class Poo {
public Poo(Po po, PoPart poPart, Part part) {
super();
this.po = po;
this.poPart = poPart;
this.part = part;
}
Po po;
PoPart poPart;
Part part;
public Po getPo() {
return po;
}
public void setPo(Po po) {
this.po = po;
}
public PoPart getPoPart() {
return poPart;
}
public void setPoPart(PoPart poPart) {
this.poPart = poPart;
}
public Part getPart() {
return part;
}
public void setPart(Part part) {
this.part = part;
}
}
最后,我的查询带有正确的语法:
<query><![CDATA[SELECT NEW de.cc.persistence.base.Poo(po, poParts, part) FROM Po po LEFT JOIN po.poParts poParts LEFT JOIN poParts.part part]]></query>