开发者

How to handle @JoinColumn in your own NamingStrategy implementation?

开发者 https://www.devze.com 2023-01-15 01:17 出处:网络
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 p

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

精彩评论

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