2016-06-16 2 views
0

그래서 난 내 데이터베이스의 모든 속성을 끌어 요청에 대한 제한된 정보를 얻기 위해 사용하려는 속성 클래스를관계를 추가하기 위해 JPA 엔티티를 확장하는 방법이 있습니까?

public class Property { 
    @Id 
    @Column(name="PROPERTY_ID") 
    private Long propertyId; 

    @Column(name="NAME") 
    private String name; 

    @Column(name="TYPE_CODE") 
    private Integer typeCode; 

    ...getters and setters... 
} 

있어요.

은 그러나 나는 또한 하나의 속성에 대한 모든 데이터를 얻을하는 데 사용할 수있는 관계

public class ExportProperty extends Property { 

    @ManyToOne 
    @JoinColumn(name="TYPE_CODE") 
    private ExportPropertyType type; 

    @OneToMany(mappedBy="property", fetch=FetchType.EAGER) 
    private Set<ExportPropertyPhoneNumber> phoneNumbers; 

    ...getters and setters... 
} 

를 만들기 위해 DB 제약을 사용하는 클래스를 원한다.

이것이 가능합니까? 아니면 내 전략을 재고해야합니까?

+0

질문에 혼란 스럽습니다. 왜 Lazy 로딩을 사용하지 않습니까? 어쨌든 열의는 대개 나쁜 생각입니다. 이렇게하면 이러한 모든 열이있는 고유 한 클래스가 하나만 있으면 JPA는 요청한 항목 만로드합니다. –

+0

거래가 진행되는 동안 코드에 액세스 할 수 없습니다. 제공된 쿼리를 사용하여 서비스를 실행하면 객체가 json으로 변환되어 다시 전송됩니다. – mike

+0

'@Inheritance (strategy = InheritanceType.TABLE_PER_CLASS) '또는 비슷한 것을 찾고 있다고 생각합니다. –

답변

0

Guillaume F. 덕분에 솔루션을 찾을 수있었습니다.

나는 어떤 공통 필드

@MappedSuperclass 
public class PropertySuper { 
    @Id 
    @Column(name="PROPERTY_ID") 
    private Long propertyId; 

    @Column(name="NAME") 
    private String name; 

    ...getters and setters... 
} 

속성 테이블

@Entity 
@Table(name = "PROPERTY") 
public class Property extends PropertySuper { 

    @Column(name="TYPE_CODE") 
    private Integer typeCode; 

    ...getters and setters... 
} 

과 JPA의 모든 링크가있는 클래스의 데이터 만 가지고 클래스를 포함하는 공통의 슈퍼 클래스가

@Entity 
@Table(name = "PROPERTY") 
public class FullProperty extends PropertySuper { 

    @ManyToOne 
    @JoinColumn(name="TYPE_CODE") 
    private FullPropertyType type; 

    @OneToMany(mappedBy="property", fetch=FetchType.EAGER) 
    private Set<FullPropertyPhoneNumber> phoneNumbers; 

    ...getters and setters... 
} 
관련 문제