不以逗号分隔的 Java JPA Left Join

JPA结构中MYSQL结构翻译错误


我有 100% 的 mysql 查询:


SELECT DISTINCT * FROM list_orders LEFT JOIN orders_translate where list_orders._id=orders_translate._order_id


query JPA String query = "SELECT t1 FROM ListOrders t1 LEFT JOIN t1.speakers e WHERE e._id = t1._id";


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 实现 Serializable {


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 查询工作正常!


富国沪深
浏览 132回答 1
1回答

长风秋雁

起初 - 如果您在 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
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java