簡體   English   中英

休眠映射

[英]Hibernate mappedBy

請告訴我為什么我錯誤地鏈接了表格。 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop信息:HHH000030:清理連接池[jdbc:oracle:thin:@ ARS-PS-DEV:1521:ars]線程“ main” java.lang中的異常.ExceptionInInitializerError:初始SessionFactory失敗org.hibernate.AnnotationException:映射通過引用未知目標實體屬性:com.ecls.ARSTools.DAO.Certificate.certificateFields中的com.ecls.ARSTools.DAO.CertificateField.сertificatecom.ecls.ARSTools.Tools .com上的.HibernateSessionFactory.buildSessionFactory(HibernateSessionFactory.java:21)在com.ecls.ARSTools.Tools.HibernateSessionFactory。(HibernateSessionFactory.java:10)在com.ecls.ARSTools.Tools.ImplARS。(ImplARS.java:14)在。 temp.AppMain.main(AppMain.java:16)

   @Entity
    @Table(name= "CERTIFICATE")
    public class Certificate implements IAvailableID{
        @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cert_generator")
        @SequenceGenerator(name="cert_generator", sequenceName = "SWS_CERTIFICATE_ID", allocationSize=1)
        @Column(name = "ID")
        private Long id;

        @Column(name= "NAME", unique = true, nullable = false, length=50)
        private String name;

        @OneToMany(targetEntity=CertificateField.class, mappedBy = "сertificate", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
        private List<CertificateField> certificateFields=new ArrayList<CertificateField>();

        public Certificate() {
            super();
        }

        public Certificate(String name, List<CertificateField> certificateFields) {
            super();
            this.name = name;
            this.certificateFields = certificateFields;
        }

        public Long getId() {
            return id;
        }
        public void setId(Long id) {
            this.id = id;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }

        public List<CertificateField> getCertificateFields() {
            return certificateFields;
        }

        public void setCertificateFields(List<CertificateField> certificateFields) {
            this.certificateFields = certificateFields;
        }

        @Override
        public String toString() {
            String res;
            res="-------------------\n";
            res+="Certificate [id=" + id + ", name=" + name+"]\n";
            for(CertificateField item:certificateFields){
                res+=item.toString()+"\n";
            }   
            return res;
        }   
    }


@Entity
@Table(name= "CERTIFICATE_FIELD")
public class CertificateField implements IAvailableID{
    @Id
    @Column(name= "ID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name= "NAME", nullable = false, length=50)
    private String name;    

    @Column(name= "VALUE", nullable = false, length=50)
    private String value;   

    @ManyToOne(targetEntity=Certificate.class, cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    @JoinColumn(name = "CERTIFICATE_ID", referencedColumnName="ID", nullable = false)
    private Certificate certificate;    

    public CertificateField(){
        super();
    }

    public CertificateField(String name, String value, Certificate certificate) {
        super();
        this.name = name;
        this.value = value;
        this.certificate = certificate;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }


    public Certificate getCertificate() {
        return certificate;
    }

    public void setCertificate(Certificate certificate) {
        this.certificate = certificate;
    }

    @Override
    public String toString() {
        return "certificate field [id=" + getId() + ", name=" + getName()+ ", value=" + getValue()+"]";
    }
}

我決定。 問題在於更新hbm2ddl的含義。 固定於<property name="hibernate.hbm2ddl.auto">auto</property>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM