»Ë»Ñ Æ÷·³
°³¹ßÀÚÆ÷·³ ÀÔ´Ï´Ù.
  • ºÏ¸¶Å© ¾ÆÀÌÄÜ

Java Hibernate Áú¹®ÀÔ´Ï´Ù4

public class Foo{
        @Id        @GeneratedValue
        @Column(columnDefinition = "int(11)", nullable = false)
        private Integer id;
        
        @Column(columnDefinition = "varchar(255)", nullable = false)
        private Integer title;
        
        @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval=true)
        @JoinColumn(name = "id")
        private List aList;
        // ÀÌÇÏ»ý·«
}

public class A{
        @Id        @GeneratedValue
        @Column(columnDefinition = "int(11)", nullable = false)
        private Integer id;

        @Column(columnDefinition = "int(11)", nullable = false)
        private Integer a_id;

        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "a_id", referencedColumnName="id", insertable=false, updatable=false)
        private Foo foo;
        // ÀÌÇÏ»ý·«
}

°ü°è´Â À§¿Í °°ÀÌ FooÀÇ id¸¦ AÀÇ a_id°¡ ÂüÁ¶ÇÏ´Â °ü°èÀÔ´Ï´Ù.

DB¿¡´Â

id                title
1                id_1
2                id_2


id                a_id
1                  1
2                  1
3                   2

ÀÌ·¸°Ô µé¾î°¡ÀÖ°í
FooÀÇ id 1ÀÎ °ÍÀ» Áö¿ì¸é AÀÇ id 1,2µµ Áö¿öÁöµµ·Ï ÇÏ°í½Í½À´Ï´Ù. (cascade)

¾î³ëÅ×À̼ǿ¡ cascade all, orphanRemoval true·Î Çسõ°í
ÇÏÀ̹ö³×ÀÌÆ®·Î foo id=1ÀÎ °ÍÀ» delete Çߴµ¥

nested exception is org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; SQL [update A set id=null where id=?]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

À§¿Í °°Àº ¿¡·¯°¡ ¹ß»ýÇϴµ¥
ã¾ÆºÁµµ ÀÌÀ¯¸¦ ¸ð¸£°Ú½À´Ï´Ù...

µµ¿ÍÁÖ½Ã¸é °¨»çÇÏ°Ú½À´Ï´Ù.

0
ÃßõÇϱ⠴ٸ¥ÀÇ°ß 0
|
°øÀ¯¹öÆ°

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ´Ï¾ó±¼¸À

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ±ò»ïÇÑ°Å

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ±ò»ïÇÑ°Å

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ¹ß±×·Ú
  • ¾Ë¸² ¿å¼³, »óó ÁÙ ¼ö ÀÖ´Â ¾ÇÇÃÀº »ï°¡ÁÖ¼¼¿ä.
©¹æ »çÁø  
¡â ÀÌÀü±Û¡ä ´ÙÀ½±Û ¸ñ·Ïº¸±â