开发者

How to handle @JoinColumn in your own NamingStrategy implementation?

I thought that joinKeyColumnName() handles @JoinColumn, but in reality I could not get it to work. I want to get rid of the necessity to write name开发者_StackOverflow="" in @JoinColumn I want the property to be used as the column name.


You don't need to specify the @JoinColumn annotation at all:

@Entity
public class PrimaryEntity {

    @OneToMany(mappedBy = "primaryEntity")
    public List<RelatedEntity> getRelatedEntities() {
        return relatedEntities;
    }

}

@Entity
public class RelatedEntity {

    @ManyToOne
    public PrimaryEntity getPrimaryEntity() {
        return primaryEntity;
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜