【问题标题】:JPA relationship ManyToMany with additional parameters带有附加参数的 JPA 关系 ManyToMany
【发布时间】:2018-06-05 13:56:14
【问题描述】:

我想使用关系表上的附加参数和不同的主键创建 JPA 关系 ManyToMany,但我仍然收到以下错误:有人可以帮我吗?谢谢

您的 SQL 语法有错误;检查手册 对应于您的 MariaDB 服务器版本,以便使用正确的语法 'order INT(11) not null auto_increment, idPoint INT(11), idPolygo' 在第 2 行

    @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;
}

【问题讨论】:

    标签: java spring spring-boot jpa mariadb


    【解决方案1】:

    'order' 是大多数 RDMBS 中的受限关键字。试试“位置”或“排序”。

    如果您真的想保留当前名称,可以尝试使用反引号进行定义:

    @Column(name = "`order`", columnDefinition = "INT(11)", nullable = false)
    private int order;
    

    【讨论】:

    • 哦,谢谢你,我没注意,你节省了我的时间!
    猜你喜欢
    • 2021-07-31
    • 2016-09-08
    • 1970-01-01
    • 2017-12-12
    • 2011-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-29
    相关资源
    最近更新 更多