|
有了 @RelationshipMetaData,图 2 对应的实体就可以被定义为:
清单 13. 应用 @RelationshipMetaData 实现图 2 的 OR 映射
@Table(name="Employee")
@Entity(name="Employee")
public class Employee {
…
@RelationshipMetaData(isSource=true,isManyToManyWithProperties=true)
@OneToMany(mappedBy=”Source”)
private java.util.Collection<Employee_owns_SoftwareLicense> owns_SoftwareLicense;
…
};
@Table(name="SoftwareLicense")
@Entity(name="SoftwareLicense")
public class SoftwareLicense{
…
@RelationshipMetaData(isSource=false,isManyToManyWithProperties=true)
@OneToMany(mappedBy=”Target”)
private java.util.Collection<Employee_owns_SoftwareLicense> Employee_owns;
…
}
@Table(name=" Employee_owns_SoftwareLicense ")
@Entity(name=" Employee_owns_SoftwareLicense ")
public class Employee_owns_SoftwareLicense{
…
@ManyToOne
private Employee Source;
@ManyToOne
private SoftwareLicense Target;
…
} |
|