Spring組件:
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 數據庫連接參數信息 -->
方言,映射描述都沒問題,
/context:component-scan
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 定義通知 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<!-- 指定目標組件中的哪些方法采用哪種事務管理方式 -->
<tx:attributes>
<tx:method name="find*" read-only="true" propagation="REQUIRED"/>
<tx:method name="get*" read-only="true" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!-- AOP配置,將通知和切入結合(目標對象) -->
<aop:config>
<!-- 將所有DAO作目標 -->
<aop:pointcut expression="within(org.dao..*)"
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory">
</property>
</bean>
<!-- 開啟事務注解配置 -->
<tx:annotation-driven transaction-manager="txManager"/>
三張表:
UserInfo_SEQ
<property name="grade" type="integer">
<column name="GRADE" />
</property>
<property name="Content" type="string">
<column name="CONTENT" />
</property>
<property name="createDate" type="date">
<column name="CREATEDATE" />
</property>
<property name="userId" type="integer" update="false"
insert="false" >
<column name="USERID" />
</property>
<property name="flag" type="integer">
<column name="FLAG" />
</property>
<!-- 指定userInfo屬性,采用many-to-one關系加載 -->
<many-to-one name="userInfo" column="USERID" lazy="false"
class="org.entity.UserInfo">
</many-to-one>
<!-- 采用一(EventGrade)對多(Event)加載信息 -->
<set name="event_Grades" >
<key column="GRADE"></key>
<one-to-many
class="org.entity.Event_Grade"/>
</set>
table="EVENT_GRADE">
UserInfo_SEQ
</class>
UserInfo_SEQ
</class>
UserInfo_SEQ
<property name="userName" type="string">
<column name="USERNAME" />
</property>
<!-- 采用一對多關系加載相關的Service記錄 -->
<set name="events" inverse="true" cascade="all">
<!-- 指定關聯條件字段,寫外鍵字段 -->
<key column="USERID"></key>
<!-- 指定要采用的關系,要加載的數據類型 -->
<one-to-many class="org.entity.Event"/>
</set>
</class>