【发布时间】:2017-10-04 00:23:53
【问题描述】:
我有一些当前使用 JPA 注释映射到数据库表的 java 模型类。其中一个是这样的:
@Table(name = "RECOG_APPLICATION_STAGING")
@SequenceGenerator(name = "seqRecogApplicationStaging", allocationSize = 0, sequenceName = "SEQ_RECOG_APPLICATION_STAGING")
@Entity
public class RecogApplicationStaging extends AuditedEntity implements Serializable {
@Id
@Column(name = "APPLICATION_ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqRecogApplicationStaging")
private Long id;
@OneToOne(mappedBy = "applicationStaging", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private RecogPropertyStaging recogPropertyStaging;
@OneToOne(mappedBy = "applicationStaging", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private ContactInformation contactInformation;
@OneToOne(mappedBy = "applicationStaging", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private RecogEligibilityStaging recogEligibilityStaging;
@OneToOne(mappedBy = "applicationStaging", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
private RecogSubmitApplStaging recogSubmitApplStaging;
@OneToMany(mappedBy = "applicationStaging", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@Sort(type = SortType.NATURAL)
private SortedSet<GenerateSignature> generateSignature = new TreeSet<>();
@Column(name = "READY_FOR_DOWNLOAD_YN")
private boolean readyForDownloadYn;
@Column(name = "RECOG_APPL_PROGRESS_CODE")
private String recogApplProgressCode;
@Column(name = "DOWNLOAD_TRACKING_NUMBER")
private String downloadTrackingNumber;
@Column(name = "PROPERTY_ID")
private Long propertyId;
//getters and setters
}
我的任务是将这些 java 模型映射到具有相同表的辅助模式。所以我正在考虑将映射移动到 hbm.xml 文件,然后为新模式合并新映射。我想知道是否可以仅将表和实体名称移动到 hbm.xml 文件中,并将文件映射保留在 java 类中。像这样的:
<hibernate-mapping package="....dao.model.recognition" default-access="field">
<class
name="....dao.model.recognition.RecogApplicationStaging"
table="RECOG_APPLICATION_STAGING"
entity-name="primaryRecogApplicationStaging">
<id name="id" column="APPLICATION_ID">
<generator class="native">
<param name="sequence_name">SEQ_RECOG_APPLICATION_STAGING</param>
</generator>
</id>
</class>
<class
name="....dao.model.recognition.RecogApplicationStaging"
table="RECOG_APPLICATION_STAGING"
entity-name="secondaryRecogApplicationStaging">
<id name="id" column="APPLICATION_ID">
<generator class="native">
<param name="sequence_name">SEQ_RECOG_APPLICATION_STAGING</param>
</generator>
</id>
</class>
这是解决这个问题的好方法还是有更好的方法来解决这个问题?我只是想避免将所有 jpa 映射转换为 hbm.xml 映射。
【问题讨论】:
-
JPA 使用
orm.xml,而不是某些 Hibernate 特定的遗物。