2010-05-27 59 views
1

我一直在努力与此相当一段时间已经。这似乎少了很多简单的比我想象这会是:从Hibernate hbm到JPA注解,一个具有挑战性的

<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,延长休眠UserType

这个工作真的很棒,但我找不到一种方法将它转换为正确的JPA,同时保持它的便利性。

有人有这种一对一映射的解决方案吗?

回答

1

看那@Embedded注释为您解决非实体对象SynchroDataType@SecondaryTable处理COTISATIONCOTISATION_SYNCHRO之间的一个一对一的映射。

+0

注释不要在非实体类忘记@Embeddable。 – qualidafial 2011-08-23 15:44:18

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; 

与SynchroData类@Embeddable