67,513
社区成员
发帖
与我相关
我的任务
分享
@Test
public void doTest(){
Session session=(Session) HibernateSessionFactory.getSession();
Transaction tx=session.beginTransaction();
try {
String hql="update House set price=price-200 where price>1500";
System.out.println("start...");
Query query=session.createQuery(hql);
int num=query.executeUpdate();
System.out.println(num);
tx.commit();
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
}finally{
session.close();
}
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="myeclipse.connection.profile">
ch06_01
</property>
<property name="dialect">
org.hibernate.dialect.OracleDialect
</property>
<property name="connection.password">123</property>
<property name="connection.username">c##scott</property>
<property name="connection.url">
jdbc:oracle:thin:@localhost:1521:orcl
</property>
<property name="connection.driver_class">
oracle.jdbc.OracleDriver
</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.cache.use_query_cache">true</property>
<mapping resource="cn/dnc/pojo/District.hbm.xml" />
<mapping resource="cn/dnc/pojo/Street.hbm.xml" />
<mapping resource="cn/dnc/pojo/Project.hbm.xml" />
<mapping resource="cn/dnc/pojo/Emolo.hbm.xml" />
<mapping resource="cn/dnc/pojo/House.hbm.xml" />
<mapping resource="cn/dnc/pojo/Users.hbm.xml" />
<mapping resource="cn/dnc/pojo/Types.hbm.xml" />
</session-factory>
</hibernate-configuration>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="cn.dnc.pojo.House" table="HOUSE">
<cache usage="read-write"/>
<id name="id" type="java.lang.Integer">
<column name="ID" precision="6" scale="0" />
<generator class="sequence">
<param name="sequence">seq_id</param>
</generator>
</id>
<many-to-one name="users" class="cn.dnc.pojo.Users" fetch="select">
<column name="USER_ID" precision="4" scale="0" />
</many-to-one>
<many-to-one name="street" class="cn.dnc.pojo.Street"
fetch="select">
<column name="STREET_ID" precision="4" scale="0" />
</many-to-one>
<many-to-one name="types" class="cn.dnc.pojo.Types" fetch="select">
<column name="TYPE_ID" precision="4" scale="0" />
</many-to-one>
<property name="title" type="java.lang.String">
<column name="TITLE" length="100" />
</property>
<property name="description" type="java.lang.String">
<column name="DESCRIPTION" length="4000" />
</property>
<property name="price" type="java.lang.Integer">
<column name="PRICE" precision="6" scale="0" />
</property>
<property name="pubdate" type="java.util.Date">
<column name="PUBDATE" length="7" />
</property>
<property name="floorage" type="java.lang.Short">
<column name="FLOORAGE" precision="4" scale="0" />
</property>
<property name="contact" type="java.lang.String">
<column name="CONTACT" length="200" />
</property>
</class>
</hibernate-mapping>