0
我有以下兩個實體,但在Trainer的oneToMany關係行中,它顯示錯誤消息「連接表trainer_batch無法找到」,而我正在使用@JoinColumn註釋。 Plggrams情況如下...爲什麼MyEclipse在編譯時顯示未找到join_table錯誤
@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>