1. 程式人生 > >hibernate 配置(樂觀鎖的配置、多對一配置)

hibernate 配置(樂觀鎖的配置、多對一配置)

<hibernate-mappingpackage="com.el.pe.model">

           <classname="ProjItemSumLine" table="EL_PE_ProjItemSumLine"optimistic-lock="version">

                     <idname="projEndLineId" column="ProjEndLineId">

                                <generatorclass="native" />

                     </id>

                     <versionname="version" column="RecVersion" type="long"/>

                <many-to-onename="projEndItemShareType" column="ProjEndItemShareTypeId"lazy="false" fetch="join" not-null="true" />

                     <many-to-onename="projItemSumLineStatus" column="LineStatusId"lazy="false" fetch="join" not-null="true" />

                     <many-to-onename="projItemSumLineSource" column="ProjEndLineSourceId"lazy="false" fetch="join" not-null="true" />

                  <many-to-onename="projItemSumLineLiabCalType"column="LineLiabCalTypeId" lazy="false"fetch="join" not-null="true" />

           </class>

</hibernate-mapping>


持有物件,樂觀鎖,多對一。....

@ManyToMany(cascade=CascadeType.ALL,targetEntity =Ability.class,fetch=FetchType.LAZY)
@JoinTable(name="EMPLOYEE_ABILITY",joinColumns={@JoinColumn(name="EMPLOYEE_ID",referencedColumnName = "id")},
inverseJoinColumns={@JoinColumn(name="ABILITY_ID",referencedColumnName="id")})

@JsonIgnore
@ManyToOne(targetEntity=Group.class,cascade=CascadeType.REFRESH,fetch = FetchType.EAGER,optional = false)
@JoinColumn(name="groupID",referencedColumnName="id",nullable=false,updatable=true)

@OneToMany(mappedBy="employee",cascade=CascadeType.ALL,targetEntity=WorkdayTable.class,fetch=FetchType.LAZY)
@JsonIgnore