sessionFactory.getCurrentSession()可以完成一系列的工作,当调用时,
hibernate将session绑定到当前线程,事务结束后,hibernate
将session从当前线程中释放,并且关闭session。当再次调用getCurrentSession
()时,将得到一个新的session,并重新开始这一系列工作。
这样调用方法如下:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Event theEvent = new Event();
theEvent.setTitle(title);
theEvent.setDate(theDate);
session.save(theEvent);
session.getTransaction().commit();
不需要close session了。.
分享到:
相关推荐
<prop key="getPlaybill">readOnly=10</prop> </props> </property> </bean> <bean id="cacheProxyFactoryBean" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name=...
<prop key="current_session_context_class">thread</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">...
<prop key="hibernate.format_sql">true</prop> </props> </property> <property name="mappingResources"> <list> <value>com/newer/pojo/CustType.hbm.xml</value> <value>...
<prop key="学号">20160233</prop> <prop key="sex">女</prop> <prop key="name">小球</prop> </props> </property> </bean> <!-- p命名空间注入属性依然要设置set方法 --> <bean id=...
<prop key="hibernate.cache.provider_class"> org.hibernate.cache.EhCacheProvider </prop> <prop key="hibernate.cache.use_query_cache">true</prop> </props> </property> </bean> <!...
<prop key="hibernate.connection.provider_class">com.jolbox.bonecp.provider.BoneCPConnectionProvider</prop> <prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop> <prop key=...
<prop key="hibernate.format_sql">true</prop> <prop key="hibernate.dialect"> org.hibernate.dialect.SQLServerDialect </prop> </props> </property> </bean> <bean id="employeeDao...
<prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> </props> </property> <property name="mappingResources"> <list> <value>vo/Users.hbm.xml</...
<property name="current_session_context_class">thread</property> <mapping resource="domain/Person.hbm.xml"/> </session-factory> </hibernate-configuration> ``` 在上述配置中,指定了 MySQL 数据库的...
<prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop> <prop key="hibernate.c3p0.min_size">5</prop> <prop key="hibernate.c3p0.max_size">20</prop> ...
<prop key="hbm2ddl.auto">update</prop> <prop key="show_sql">true</prop> </props> </property> <property name="mappingResources"> <list> <value>...
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> </props> </property> ...
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean> ``` - **通用事务配置** 为了进一步简化代码并提高可重用性,可以创建一个抽象的事务配置Bean,用于统一管理所有...
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean> ``` 在上面的代码中,我们定义了一个名为transactionInterceptor的bean,这个bean使用TransactionInterceptor来拦截事务...
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.cglib.use_reflection_optimizer">true</prop> </props> </...
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <bean id="transactionManager" class="org.spring...
<prop key="passwordCallbackRef">passwordCallback</prop> </props> </property> </bean> <jaxws:endpoint ...> <cxf:features> <bean id="wss4j" class="org.apache.cxf.ws.security.wss4j.WSS4...
<prop key="org.quartz.threadPool.threadCount">5</prop> <prop key="org.quartz.threadPool.threadPriority">5</prop> </props> </property> </bean> ``` #### 四、总结 通过上述配置,不仅可以在 Spring ...
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.jdbc.batch_...
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.cglib.use_reflection_optimizer">true</prop> </props> </...