Java JPA Left Join,不用逗号分隔

时间:2019-01-20 20:06:06

标签: java mysql jpa

JPA结构中的MYSQL结构转换中的错误

我有100%工作的mysql查询:

SELECT DISTINCT * FROM list_orders左联接orders_translate其中list_orders._id = orders_translate._order_id

查询JPA 字符串查询=“从ListOrders t1左连接t1.speakers e WHERE e._id = t1._id中选择SELECT t1”;

public class OrdersTranslate implements Serializable {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "_id")
private Long id;
@Size(max = 50)
@Column(name = "_english_name")
private String englishName;
@Size(max = 50)
@Column(name = "_arabic_name")
private String arabicName;
@Size(max = 50)
@Column(name = "_russian_name")
private String russianName;
@Size(max = 50)
@Column(name = "_french_name")
private String frenchName;
@Basic(optional = false)
@NotNull
@Column(name = "_order_id")
private int order_id;

}

公共类ListOrders实现可序列化的{

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "_id")
@SerializedName("_id")
private Integer id;
@Basic(optional = false)
@NotNull
@Column(name = "_number_id")
@SerializedName("_number_id")
private int numberId;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 50)
@Column(name = "name")
@SerializedName("name")
private String name;
@OneToOne(cascade = CascadeType.ALL)
private List<OrdersTranslate> speakers;

}

我收到下一个错误:

[53,54] FROM子句具有'ListOrders t1 LEFT JOINN t1.oerders'和'e',它们之间没有逗号分隔。 [42,53]标识变量't1.oerders'不遵循Java标识符的规则。 [56,56]必须为范围变量声明提供标识变量。

JPA查询有什么问题? MySQL查询正常工作!

1 个答案:

答案 0 :(得分:0)

首先-如果ListOrders表中有OrdersTranslate数组,则没有OneToOne联接。这是OneToMany联接。

请尝试您的ListOrders类:

@OneToMany(mappedBy="listOrders")
private List<OrdersTranslate> speakers;

在您的OrdersTranslate类中:

@ManyToOne
@JoinColumn(name = "_order_id")
private ListOrders listOrders;

然后您的JPA查询将显示:

SELECT t1 FROM ListOrders t1 LEFT JOIN t1.speakers e