当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Is determinePrimaryKeyJoinColumnName() ever used in Hibernate 5 ImplicitNamingStrategy?

问题描述:

I am working on hibernate 5 and implemented the ImplicitNamingStrategy interface. Among other methods, there are two methods called determinePrimaryKeyJoinColumnName(...) and determineJoinColumnName(...). In the java doc, it says about determinePrimaryKeyJoinColumnName:

Determine the column name related to {@link javax.persistence.PrimaryKeyJoinColumn}. In

* {@code hbm.xml} terms, this would be a {@code } defined for a {@code }

* or a {@code } (others?)

I annotated my joins with PrimaryKeyJoinColumn and the code works, however the names never get routed through determinePrimaryKeyJoinColumnName(...) but through determineJoinColumnName(...).

Am I wrong in believing this is a bug?

网友答案:

@PrimaryKeyJoinColumn can be used like @JoinColumn only for the @OneToOne mapping. In such situation an additional join column is not used and, of course, the name of such "not existing column" is not generated.

@PrimaryKeyJoinColumn can be used for an inheritance too. For an example

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "someDiscriminator")
public class Customer {

    @Id
    @GeneratedValue
    private Long customerPid;

    @Column
    private String customerName;

}

@Entity
@PrimaryKeyJoinColumn(name = "xxxYY")
public class ValuedCustomer extends Customer {

    @Column
    private String valuedCustomerName;

}

Hibernate will use xxxYY for a column name. But if you do not specify a name

@Entity
@PrimaryKeyJoinColumn
public class ValuedCustomer extends Customer {

    @Column
    private String valuedCustomerName;

    }

}

Hibernate will not use determinePrimaryKeyJoinColumnName() to generate a name. So, looks like, it is a bug.

Hibernate calls determinePrimaryKeyJoinColumnName() only in one place Ejb3JoinColumn.java#L719. But I can't get in which situations this happens.

I have encountered such problems too, when try to implement an adapter of Hibernate 4 NamingStrategy for Hibernate 5. You can refer ImprovedNamingStrategy for Hibernate 5 for an additional notes.

And my try to implement Hibernate 5 Implicit Naming Strategy.

分享给朋友:
您可能感兴趣的文章:
随机阅读: