我已经在这个问题上苦苦挣扎了很长时间。它似乎不像我想象的那么简单:
<join table="COTISATION_SYNCHRO" fetch="join" optional="true">
<key column="COTISATION_SYNCHRO_COTISATION_ID_FK" on-delete="noaction"/>
<property name="cotisationCoupon" type="java.lang.Long" update="true" insert="true">
<column name="COTISATION_COUPON" not-null="true" unique="true"/>
</property>
<property name="synchroData" type="com.allence.opcapl.alpha2.common.model.synchro.SynchroDataType">
<column name="LAST_ACCESS_LOCAL" not-null="true"/>
<column name="LAST_UPDATE_LOCAL" not-null="true"/>
<column name="LAST_ACCESS_REMOTE" not-null="true"/>
<column name="LAST_UPDATE_REMOTE" not-null="true"/>
</property>
</join>
这包含在COTISATION
表格映射中,并使用SynchroDataType
,扩展了Hibernate UserType
。
这非常好用,但是我找不到一种方法将它翻译成适当的JPA,同时保持它的便利性。
有人有这种一对一映射的解决方案吗?
答案 0 :(得分:1)
查看@Embedded注释以解决非实体对象SynchroDataType
和@SecondaryTable以处理COTISATION
和{{1}之间的一对一映射}}
答案 1 :(得分:0)
非常感谢,我让它发挥作用。 我专注于@JoinTable,方向错误。 @secondaryTable做了这个伎俩。
这是解决方案:
@Entity
@Table(name = "COTISATION")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@SecondaryTable(name = "COTISATION_SYNCHRO", pkJoinColumns = @PrimaryKeyJoinColumn(name = "COTISATION_SYNCHRO_COTISATION_ID_FK"))
public class Cotisation {
...
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "lastAccessLocal", column = @Column(name = "LAST_ACCESS_LOCAL", table = "COTISATION_SYNCHRO")),
@AttributeOverride(name = "lastUpdateLocal", column = @Column(name = "LAST_UPDATE_LOCAL", table = "COTISATION_SYNCHRO")),
@AttributeOverride(name = "lastAccessRemote", column = @Column(name = "LAST_ACCESS_REMOTE", table = "COTISATION_SYNCHRO")),
@AttributeOverride(name = "lastUpdateRemote", column = @Column(name = "LAST_UPDATE_REMOTE", table = "COTISATION_SYNCHRO"))
})
private SynchroData synchroData;
@Column(name = "COTISATION_COUPON", table = "COTISATION_SYNCHRO", unique = true)
private Long cotisationCoupon;
使用@Embeddable
注释的SynchroData类