2010-05-27 58 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