1

抽象クラスから継承し、親子関係を持つ 2 つのクラスがあります。

したがって、注釈 OneToMany と ManyToOne を使用しますが、子クラスの親エンティティは常に null です。誰かが私を助けてくれますか.

これらは私のクラスのコードです:

public @Table(name="flowentity") @Entity abstract class FlowEntity {

final static Logger log = LoggerFactory.getLogger(FlowEntity.class);

//Globals informations concerning the flow state
private @Id @GeneratedValue(strategy = GenerationType.IDENTITY) Integer flowId = 0;
private String flowName;

private @OneToMany(fetch=FetchType.EAGER, cascade=CascadeType.ALL) 
        Set<PeopleEntity> actorSet = new HashSet<>();


//Global parameters for most of flows
//Organizational parameters
private @OneToOne(fetch=FetchType.EAGER, cascade=CascadeType.ALL)
        @JoinColumn(name="organisationalEntity_Id")
        OrganisationalEntity organisationalEntity;

...

public @Table(name="ams_newCPEntity") @Entity class NewMultiCPEntity  extends FlowEntity {

private @OneToMany(targetEntity=NewCPEntity.class, fetch=FetchType.EAGER, cascade=CascadeType.ALL,mappedBy="parent") 
        Set<NewCPEntity> cpList = new HashSet<NewCPEntity>();

//Constructor
    public NewMultiCPEntity(){
        setFlowName(EnumFlow.N_CP_M.getFlowAcronym());
    }

...

public @Table(name="ams_newCPEntity") @Entity class NewCPEntity extends FlowEntity {

final static Logger log = LoggerFactory.getLogger(NewCPEntity.class);

private boolean formNCPValidated;

private @ManyToOne @JoinColumn(name="parent_Id", nullable=false)
        NewMultiCPEntity parent;

public NewCPEntity(){
    log.debug("Instanciation of a new CP");
    setFlowName(EnumFlow.N_CP.getFlowAcronym());
}

public @Override OrganisationalEntity getOrganisationalEntity(){
    return parent.getOrganisationalEntity();
}

...

@JoinColumn アノテーションを追加しないと、JPA は関連付けテーブルを作成しますが、親を取得することはできませんが、関連付けはデータベースで要求することによって直接行うことができます。

助けてくれてどうもありがとう。

よろしく、

4

1 に答える 1