我有以下两个实体。但是在 oneToMany 关系行的 Trainer 中,它显示错误消息“无法找到加入表 trainer_batch”,而我正在使用 @JoinColumn 注释。Plggrams如下...
@实体
@Table(name="培训师")
公共类培训师{
@ID
@GeneratedValue(strategy=GenerationType.IDENTITY)
内部标识;
字符串名称;
@OneToMany(级联=CascadeType.ALL)
@JoinColumn(name="trainerid")
设置批次=new HashSet();
公共字符串 getName() {
返回名称;
}
公共无效集合名称(字符串名称){
this.name = 名称;
}
公共设置 getBatches() {
退货批次;
}
公共无效setBatches(批量){
批次。添加(批次);
}
}
@实体
@Table(name="批次")
公共类批次{
公共字符串 getSlot() {
返回槽;
}
公共无效setSlot(字符串槽){
this.slot = 插槽;
}
公共字符串 getTopic() {
返回主题;
}
公共无效 setTopic(字符串主题){
this.topic = 主题;
}
@ID
@GeneratedValue(strategy=GenerationType.IDENTITY)
内部标识;
字符串槽;
字符串主题;
}
persistance.xml 如下
<?xml 版本="1.0" 编码="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>
<属性>
<属性名称=“hibernate.connection.driver_class”值=“com.microsoft.sqlserver.jdbc.SQLServerDriver”/>
<property name = "hibernate.connection.url" value = "jdbc:sqlserver://localhost:1433;DatabaseName=test; MARS_Connection=yes;"/>
<属性名称=“hibernate.connection.username”值=“sa”/>
<属性名称=“hibernate.connection.password”值=“测试”/>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
</属性>
</persistence-unit>
</持久性>