사용자 도구

사이트 도구


java:jpa:index

문서의 이전 판입니다!


JPA and Index

  • JPA 2.1 부터 Table Index 설정을 애노테이션으로 할 수 있게 되었다.

@Annotations

@ForeinKey

  • @ForeinKey(ConstaintMode.NO_CONSTRAINT)를 통해서 외래키를 의도적으로 생성하지 않을 수 있어야 한다.
  • Hibernate 4.x, 5.x 일부에서 양방향(bidirectional) 관계에서 @ForeinKey(ConstaintMode.NO_CONSTRAINT)가 먹지 않는 문제가 있다. - [HHH-8805] [SchemaUpdate] javax.persistence.ForeignKey doesn't respect ConstraintMode.NO_CONSTRAINT
    // 버그가 해결 될 때까지 부모측에서 @org.hibernate.annotations.ForeignKey 를 함께 사용해야 한다.
    // parent side
        @OneToMany(
                cascade = CascadeType.ALL,
                fetch = FetchType.LAZY,
                mappedBy = "parent",
                orphanRemoval = true
        )
        // do not use a foreign key constraint, because it's not compatible with partitioning.
        // needed on both sides of the relationship, but it doesn't look like jpa allows you
        // to use @javax.persistence.ForeignKey on the mappedBy side, so we use deprecated hibernate
        // version.
        @org.hibernate.annotations.ForeignKey(name = "none")
        public List<Child> getChildren() {
            return _children;
        }
     
    // child side
        @ManyToOne
        @JoinColumn(
                // do not use a foreign key constraint, because it's not compatible with partitioning
                foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT)
        )
        public Parent getParent() {
            return _parent;
        }
java/jpa/index.1530517857.txt.gz · 마지막으로 수정됨: 2018/07/02 16:50 저자 kwon37xi