直接看代码
Session session = HibernateSessionFactory.getSession();
//Transaction tx = session.beginTransaction();
//System.out.println(session.getFlushMode());
WapOperation wapoperation = new WapOperation();
wapoperation.setCode(7l);
wapoperation.setDescription("111122211");
opdao.save(wapoperation);
//opdao.delete(wapoperation);
//tx.commit();为什么在save的时候不需要事务提交,数据就更新到数据库中了~而update和delete是需要用事务commit后才更新到数据为什么save不需要?????? 谁能给我解释下~ 有办法让save也需要事务提交后才生效吗?
Session session = HibernateSessionFactory.getSession();
//Transaction tx = session.beginTransaction();
//System.out.println(session.getFlushMode());
WapOperation wapoperation = new WapOperation();
wapoperation.setCode(7l);
wapoperation.setDescription("111122211");
opdao.save(wapoperation);
//opdao.delete(wapoperation);
//tx.commit();为什么在save的时候不需要事务提交,数据就更新到数据库中了~而update和delete是需要用事务commit后才更新到数据为什么save不需要?????? 谁能给我解释下~ 有办法让save也需要事务提交后才生效吗?
具体不是太记得了。楼主可以去了解下hibernate中的各个参数的含义,绝对能解决问题。太久没有用过hibernate了不太记得啦
楼主去了解下hibernate的 cascade与inverse属性。
解决问题后烦请告知下。本人也想知道为什么,对hibernate一直没有深入去研究过
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/wapzj
</property>
<property name="connection.username">111</property>
<property name="connection.password">111</property>
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="myeclipse.connection.profile">wapzj</property>
<property name="hibernate.jdbc.batch_size">200</property>
<property name="show_sql">true</property>
<class name="com.rifetune.wapzj.common.pojo.WapOperation" table="wap_operation" catalog="wapzj">
<id name="code" type="java.lang.Long">
<column name="code" />
<generator class="identity"></generator>
</id>
<property name="description" type="java.lang.String">
<column name="description" length="200" not-null="true" />
</property>
<set name="privilege" table="wap_priv_op" cascade="none">
<key column="o_code" />
<many-to-many class="com.rifetune.wapzj.common.pojo.WapPrivilege" column="p_code"
outer-join="auto"/>
</set>
</class>
</hibernate-mapping>
除非你是在同一个session中,要不然不可能看到。
请问LZ你去库里看了没?
真正保存进去了吗?