用程序。因此,对优化不执行并排迁移。相反 ,先迁移常见配置参数,然后让负载测试指示需要引入哪些 OpenJPA 优化参数。
本文没有介绍 Hibernate 查询到 OpenJPA 的迁移,因为对于 Hibernate 应用程序来说,具有满足业 务需求的定义良好的域模型是比较普遍的。对于没有定义良好的域模型和需要许多特殊查询的应用程序, 则解决方案(如 iBatis)比对象关系映射工具(如 Hibernate 或 OpenJPA)更合适。也就是说,如果有 足够的兴趣,则后续文章可能将介绍 Hibernate 查询到 OpenJPA 的迁移。
附录:OpenJPA Java 5 注释
注释 A. 单个表继承
//Participant (base) class
@Entity
@Table(name="T_PRTCPNT")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="PRTCPNT_CLASS")
public class Participant implements java.io.Serializable {
@Column(name="PRTCPNT_TID")
@Id private Long participantId;
...
}
// SalesRep subclass
@Entity
@DiscriminatorValue(value="SALES_REP")
public class SalesRep extends Participant {
...
}
// Administrator subclass
@Entity
@DiscriminatorValue(value="ADMIN")
public class Administrator extends Participant {
...
}
将遗留Hibernate应用程序迁移到OpenJPA和EJB 3.0(二)(15)
时间:2011-09-18 Donald Vines
注释 B. 连接继承
// Participant (base) class
@Entity
@Table(name="T_PRTCPNT")
@Inheritance(strategy=InheritanceType.JOINED)
public class Participant implements Serializable {
@Column(name="PRTCPNT_TID")
@Id private Long participantId;
...
}
// SalesRep subclass
@Entity
@Table(name="T_SALESREP")
@PrimaryKeyJoinColumn(name="PRTCPNT_TID")
public SalesRep extends Participant {
...
}
// Administrator subclass
@Entity
@Table(name="T_ADMIN")
@PrimaryKeyJoinColumn(name="PRTCPNT_TID")
public Administrator extends Participant {
...
}
注释 C. 可嵌入对象的一对一关系
// Employee (parent) class
@Entity
@Table(name="T_EMPLOYEE")
public class Employee implements Serializable {
@Embedded private EmployeeRecord employeeRec;
...
}
// EmployeeRecord (child) class
@Embeddable
public class EmployeeRecord implements Serializable {
...
}
注释 D. 多对一关系
// Address (parent) class
@Entity
@Table(name="T_ADDRESS")
public class Address implements Serializable {
...
@Column(name="ADDR_TID")
@Id private Long addressId;
}
// Phone (child) class
@Entity
@Table(name="T_PHONE")
public class Phone implements Serializable {
...
@ManyToOne
@JoinColumn(name="ADDR_TID")
private Address address;
...
}
将遗留Hibernate应用程序迁移到OpenJPA和EJB 3.0(二)(16)
时间:2011-09-18 Donald Vines
注释 E. 一对多关系
// Address (parent) entity
@Entity
@Table(name="T_ADDRESS")
public class Address implements Serializable {
...
@OneToMany(mappedBy="address", cascade=CascadeType.ALL)
private Set<Phone> phones = new HashSet<Phone>();
...
@Column(name="ADDR_TID")
@Id private Long addressId;
}
// Phone (child) entity
@Entity
@Table(name="T_PHONE")
public class Phone implements Seria
|