2017-12-18 6 views
-1

최대 절전 모드 4.3.8을 사용 중입니다. 자바 스프링 웹 앱과 postgres db.기존 레코드에 외래 키가있는 최대 절전 모드 엔티티 생성

나는 B와 C

을 기록하는 두 개의 외래 키와 기록 A를이 기록 B가 이미 시스템에 존재

. 레코드 C는 새 레코드이며 레코드 A를 저장할 때 추가됩니다. 레코드 A 레이아웃입니다.

A.primaryKey 
A.foreignKey to B.primaryKey (already exists in system) 
A.foreignKey to C.primaryKey (new record) 
A.feildX 

레코드 A를 어떻게 저장합니까? 당신의 도움이 여기에

에 대한

덕분에 classes.I이 오류를 설명하는 최대 절전 모드에 새로운 오전 엔티티입니다.

@Entity 
@Table(name="atable") 
public class Aclass { 

    @Id 
    @Column(name="arec_id") 
    private String id; 

    //Do not create a reference to the bclass in this object. however do write the bclass object with a foreign key reference back to this aclass object 
? @Transient 
? @OneToOne(cascade=?) 
? @JoinTable(name="btable",[email protected](name="brec_id")) 
? private Bclass bclass; 

    //Create a reference to the cclass object in this record and write the cclass object as well 
    @OneToOne(cascade=CascadeType.ALL) 
    @JoinColumn(name="crec_foreign_key",referencedColumnName="crec_id") 
    private Cclass cclass; 

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

    private VoiceEngineModel voiceEngineModel; 

} 

@Entity 
@Table(name="btable") 
public class Bclass { 

    @Id 
    @Column(name="brec_id") 
    private String id; 

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

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


} 

@Entity 
@Table(name="ctable") 
public class Cclass { 

    @Id 
    @Column(name="crec_id") 
    private String id; 

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


} 
+0

후 귀하의 엔티티 클래스뿐만 아니라 지속성 코드의 소스 코드, 당신은 아직이있는 경우 –

답변

0

해결책을 찾았습니다. 아주 쉽게. Bclass의 원본 코드가 잘못되었습니다. 죄송합니다.

  1. Bclass은 (이름 = "btable") 열이

    @Entity @Table 참조 수정에 대한 Aclass

  2. 에 Bclass하는 공용 클래스 Bclass {

    @Id을 모든 참조를 제거 @Column (name = "brec_id") 전용 문자열 ID.

    @ManyToOne @JoinColumn (name = "aref") private Aclass aref;

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

    }