为什么MyEclipse在编译时显示join_table未找到错误

时间:2012-12-19 02:37:17

标签: java hibernate myeclipse

我有两个实体。但是在oneToMany关系行的Trainer中,它显示错误消息“无法找到连接表trainer_batch”,而我正在使用@JoinColumn注释。 Plggrams如下......

@Entity
@Table(name="trainer")
public class Trainer {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    int id;
    String name;
    @OneToMany(cascade=CascadeType.ALL)
    @JoinColumn(name="trainerid")
    Set batches=new HashSet();
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Set getBatches() {
        return batches;
    }
    public void setBatches(Batch batch) {
        batches.add(batch);
    }


}


@Entity
@Table(name="batch")
public class Batch {

    public String getSlot() {
        return slot;
    }
    public void setSlot(String slot) {
        this.slot = slot;
    }
    public String getTopic() {
        return topic;
    }
    public void setTopic(String topic) {
        this.topic = topic;
    }
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    int id;
    String slot;
    String topic;

}

persistance.xml如下


<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">

    <persistence-unit name="one_to_many_pk_fkPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name = "hibernate.connection.driver_class" value = "com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
            <property name = "hibernate.connection.url" value = "jdbc:sqlserver://localhost:1433;DatabaseName=test; MARS_Connection=yes;"/>
            <property name = "hibernate.connection.username" value = "sa"/>
            <property name = "hibernate.connection.password" value = "test"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
        </properties>
    </persistence-unit>

</persistence>

1 个答案:

答案 0 :(得分:0)

你应该使用generic作为Batch。 用户关系如下: 设置&LT;批量&GT; batches = new HashSet&lt; Batch&gt;();