Hibernate ConstraintViolationException:ON DELETE NO ACTION ON UPDATE NO ACTION

时间:2017-07-17 09:55:51

标签: java mysql spring hibernate jpa

我正在使用Java,Spring,Hibernate,JPA。

  +--------------+      +-----------------+    +-------------------+
  |   map_range  |      |  map_location   |    |   location_map    |
  +--------------+      +-----------------+    +-------------------+
  |     ID       |      |     MAP_ID      |    |      ID           |
  |     RANGE    |      |     LOC_ID      |    |     LATITUDE      |
  |     RADIUS   |      |                 |    |     LONGITUDE     |
  +--------------+      +-----------------+    +-------------------+

MapRange.java

@Entity
@Table(name = "map_range")
@XmlRootElement(name = "map_range")
public class MapRange extends AbstractDomain<Long> {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Size(min = 1, max = 100)
    @Column(name = "NAME", nullable = false)
    private String name;

    @Column(name = "RADIUS", nullable = false)
    private Integer radius;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
    @JoinTable(name = "map_location", joinColumns = {
            @JoinColumn(name = "MAP_ID", referencedColumnName = "ID") }, inverseJoinColumns = {
                    @JoinColumn(name = "LOC_ID", referencedColumnName = "ID", unique = true) })
    private Set<LocationMap> locations;

LocationMap.java

@Entity
@Table(name = "location_map")
@XmlRootElement(name = "location_map")
public class LocationMap extends AbstractDomain<Integer> {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID", unique = true, nullable = false)
    private Integer id;

    @Column(name = "LATITUDE", nullable = false)
    private BigDecimal latitude;

    @Column(name = "LONGITUDE", nullable = false)
    private BigDecimal longitude;

当我致电以下时间时:

super.merge(mapRange);

    BeanUtils.copyProperties(entity, attached);
    entityManager.setFlushMode(FlushModeType.COMMIT);
    attached = entityManager.merge(attached);

我收到以下错误:

11:45:11,577 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-5)
     

SQL错误:1452,SQLState:23000       11:45:11,578 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper](默认任务-5)   无法添加或更新子行:外键约束失败   (ebdbmap_location,CONSTRAINT fk_map_loc_map FOREIGN KEY   (LOC_ID)参考map_rangeID)在更新时不执行任何操作   没有行动)       11:45:11,578 INFO [org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl](默认   任务-5)HHH000010:在批量发布时它仍然包含JDBC   声明       11:45:11,579 ERROR [org.hibernate.internal.ExceptionMapperStandardImpl](默认任务-5)   HHH000346:托管刷新期间出错   [org.hibernate.exception.ConstraintViolationException:不能   执行声明]

如果有人能就如何解决这个问题提出一些建议,我将不胜感激。

0 个答案:

没有答案