java - 带有附加参数的 JPA 关系 ManyToMany
问题描述
我想使用关系表上的附加参数和不同的主键来建立 JPA 关系 ManyToMany,但我仍然收到以下错误:有人可以帮我吗?谢谢
您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以在第 2 行的“order INT(11) not null auto_increment, idPoint INT(11), idPolygo”附近使用正确的语法
@Entity
@Table(name = "Point")
public class Point implements Serializable{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "idPoint", columnDefinition = "INT(11)", nullable = false)
private int idPoint;
@Column(name = "lat", columnDefinition = "DOUBLE(10,8) ", nullable = true)
private double lat;
@Column(name = "lng", columnDefinition = "DOUBLE(10,8)", nullable = true)
private double lng;
//relationship OneToMany with table PolygonHasPoint
@OneToMany(mappedBy="point")
private Set<PolygonHasPoint> polygonHasPoint;
}
@Entity
@Table(name = "Polygon")
public class Polygon implements Serializable{
//primary key : idPolygon
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "idPolygon", columnDefinition = "INT(11)", nullable = false)
private int idPolygon;
//relationship OneToMany with table PolygonHasPoint
@OneToMany(mappedBy="polygon")
private Set<PolygonHasPoint> polygonHasPoint;
}
@Entity(name="Point_Polygon")
@Table(name = "Polygon_Point")
public class PolygonHasPoint implements Serializable{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "order", columnDefinition = "INT(11)", nullable = false)
private int order;
@ManyToOne
@JoinColumn(name = "idPoint", columnDefinition = "INT(11)", nullable = true)
private Point point;
@ManyToOne
@JoinColumn(name = "idPolygon", columnDefinition = "INT(11)", nullable = true)
private Polygon polygon;
}
解决方案
'order' 是大多数 RDMBS 中的受限关键字。尝试“位置”或“排序”。
如果您真的想保留当前名称,可以尝试使用反引号进行定义:
@Column(name = "`order`", columnDefinition = "INT(11)", nullable = false)
private int order;
推荐阅读
- android - 使用 Kotlin 在 Android Studio 中使用 Firestore 的收藏夹列表
- c++ - 在没有 API 的情况下使用谷歌翻译文本
- excel - 带有显示警报的 VBA 删除工作表 False 仍然从另一个工作簿发出警报
- powershell - Powershell xaml RichText 窗口未实时更新
- python - 答案只是在 python 中打印 .0 而不是 .00
- symfony - 在 symfony 项目的 LDAP 连接后向用户添加角色
- arrays - 数组下标超出范围在 SAS 中的行错误
- android - 如何检查字符串是否只有一个指定字符?
- r - 替换 htmltools::tag 的属性值
- c# - 学习 .net core 3.1 - 第一次尝试使用 API webservice