【问题标题】:Can I add many to one mapping in Embeddable class我可以在 Embeddable 类中添加多对一映射吗
【发布时间】:2016-05-22 03:07:39
【问题描述】:

我可以在 Embeddable 类中添加多对一映射吗? 在这里,它试图直接获取值 jobCategoryMast。 这是一个映射对象。

抛出异常 org.postgresql.util.PSQLException: ERROR: 列 jobvaccina0_.jobcategorymast 不存在

@Entity
@Table(name="job_vac",schema="cis")
@SuppressWarnings("serial")
public class JobVacc implements java.io.Serializable {


    // Fields    
     @Column(name="default", length=1)
     private String default;

     @EmbeddedId
     private JobVaccPK jobVaccinationPK;

     public JobVacc(){

     }
     //getters and setters
     }

// JobVaccPK 类

@Embeddable
@SuppressWarnings("serial")
public class JobVaccPK implements Serializable{

    /*@Column(name = "job_category_id")
    private Long jobCategoryId;*/
    private JobCategoryMast jobCategoryMast;

    @Column(name = "vaccination_id")
    private Long vaccId;


    @Column(name = "screening_type_id")
    private Long screeningTypeId;


    /**
     * @return the jobCategoryMast
     */
    public JobCategoryMast getJobCategoryMast() {
        return jobCategoryMast;
    }

    /**
     * @param jobCategoryMast the jobCategoryMast to set
     */
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="job_category_id")
    public void setJobCategoryMast(JobCategoryMast jobCategoryMast) {
        this.jobCategoryMast = jobCategoryMast;
    }
    //other setters and getters

【问题讨论】:

    标签: spring spring-mvc jpa hibernate-mapping


    【解决方案1】:

    JPA 2.0 spec

    不支持在嵌入式 id 类中定义的关系映射。

    尽管您的 JPA 提供商可能会支持它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-22
      • 2020-05-06
      • 2021-04-24
      • 1970-01-01
      • 2015-12-21
      • 1970-01-01
      • 2011-08-24
      相关资源
      最近更新 更多