How to define unidirectional OneToMany relationship in JPA

前端 未结 1 1963
情深已故
情深已故 2020-12-02 09:56

I have a following problem with entity mapping in JPA. I have two entities, first one is Lookup and the second is Text which represents translations for entities. Now I need

相关标签:
1条回答
  • 2020-12-02 10:31

    My bible for JPA work is the Java Persistence wikibook. It has a section on unidirectional OneToMany which explains how to do this with a @JoinColumn annotation. In your case, i think you would want:

    @OneToMany
    @JoinColumn(name="TXTHEAD_CODE")
    private Set<Text> text;
    

    I've used a Set rather than a List, because the data itself is not ordered.

    The above is using a defaulted referencedColumnName, unlike the example in the wikibook. If that doesn't work, try an explicit one:

    @OneToMany
    @JoinColumn(name="TXTHEAD_CODE", referencedColumnName="DATREG_META_CODE")
    private Set<Text> text;
    
    0 讨论(0)
提交回复
热议问题