Java 如何在自己的NamingStrategy实现中处理@JoinColumn?

Java 如何在自己的NamingStrategy实现中处理@JoinColumn?,java,hibernate,persistence,Java,Hibernate,Persistence,我原以为joinKeyColumnName()处理@JoinColumn,但实际上我无法让它工作。我希望不必在@JoinColumn中写入name=”“,我希望将属性用作列名。您根本不需要指定@JoinColumn注释: @Entity public class PrimaryEntity { @OneToMany(mappedBy = "primaryEntity") public List<RelatedEntity> getRelatedEntities()

我原以为
joinKeyColumnName()
处理
@JoinColumn
,但实际上我无法让它工作。我希望不必在
@JoinColumn
中写入
name=”“
,我希望将属性用作列名。

您根本不需要指定@JoinColumn注释:

@Entity
public class PrimaryEntity {

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

}

@Entity
public class RelatedEntity {

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

}
@实体
公共类主要实体{
@OneToMany(mappedBy=“primaryEntity”)
公共列表getRelatedEntities(){
返回相关实体;
}
}
@实体
公共类关联实体{
@许多酮
公共PrimaryEntity getPrimaryEntity(){
返回主实体;
}
}

您根本不需要指定@JoinColumn注释:

@Entity
public class PrimaryEntity {

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

}

@Entity
public class RelatedEntity {

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

}
@实体
公共类主要实体{
@OneToMany(mappedBy=“primaryEntity”)
公共列表getRelatedEntities(){
返回相关实体;
}
}
@实体
公共类关联实体{
@许多酮
公共PrimaryEntity getPrimaryEntity(){
返回主实体;
}
}