我正在使用spring框架4.2.5.RELEASE和Hibernate 5进行项目开发,我试图用两个表映射一个实体,我有这样的东西:

@Entity
@Table(name = "programa")
@SecondaryTable(name="jornada", pkJoinColumns={
    @PrimaryKeyJoinColumn(name="jor_codigo",   referencedColumnName="jor_codigo") })
public class Programa {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "pro_codigo")
    private int id;

    @Column(name = "pro_calendario")
    private Character calendario;

    @Column(name = "pro_registro_snies")
    private String codigoSnies;

    @Column(name = "jor_nombre", table = "jornada")
    private String jornada;

    @Column(name = "pro_propio")
    private boolean propio;

    @ManyToOne
    @JoinColumn(name = "sed_codigo")
    private Sede sede;

    @Column(name = "pro_titulo_otorgado")
    private String tituloOtorgado;

    @OneToOne
    @JoinColumn(name = "uaa_codigo")
    private Uaa uaa;
    //Setters and getters
}


我正在用junit进行测试,但出现此错误:

Unable to find column with logical name: jor_codigo in org.hibernate.mapping.Table(programa) and its related supertables and secondary tables


希望您能对此有所帮助,谢谢。

编辑

这些表的列是:
 节目专栏:


pro_codigo->主键
pro_nombre
jor_codigo->外键


jornada专栏:


jor_codigo->主键
jor_nombre

最佳答案

 @PrimaryKeyJoinColumn(name="jor_codigo",   referencedColumnName="jor_codigo")


您的referencedColumnName应该是pro_codigo。这样在jor_codigo
jornada可以引用它。

07-24 22:16