做的是类似留言版的东东,User 是用户表的映射,Message帖子表的映射
很郁闷!!!!!
很郁闷!!!!!
解决方案 »
- hibernate sjf4j的使用
- html跳转到servlet时如何带参数传递!!(没有表单)
- 关于面向对象,两年了还是没弄明白
- xml中的一个问题
- 高手来帮帮ibatis的问题
- 一个sql变成hql,搞了n久,请教高人
- Servlet actionServlet is not available
- RMI问题:绑定对象到RMI注册表的时候,报告stub没找到,怎么办?
- SOS SOS .......急急急。。。。。。。。。为什么Jsp 访问数据库出错??
- 大佬们,终端通过socket实时上传视频到服务器,服务端这边该怎么处理?直接把流推给观看方吗?
- struts2+spring2 事务问题 4天了找遍了internet也没有解决
- 哪出了问题?
log.debug("saving Message instance");
try {
getSession().save(transientInstance);
System.out.println("save successful");
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}System.out.println("save successful");
这个都打印了
message.hbm.xml
<!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="connection.username">root</property>
<property name="connection.url">
jdbc:mysql://localhost/accp
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">mys</property>
<property name="connection.password">my</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="show_sql">true</property>
<mapping resource="com/accp/User.hbm.xml" />
<mapping resource="com/accp/RReply.hbm.xml" />
<mapping resource="com/accp/Message.hbm.xml" /> </session-factory></hibernate-configuration>Message.hbm.xml<?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="com.accp.Message" table="message" catalog="accp">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="increment" />
</id>
<many-to-one name="user" class="com.accp.User" fetch="select">
<column name="user_id" unique="true" />
</many-to-one>
<property name="context" type="java.lang.String">
<column name="context" length="30" />
</property>
<property name="title" type="java.lang.String">
<column name="title" length="32" />
</property>
<property name="pubDate" type="java.lang.String">
<column name="pub_date" length="20" />
</property>
<property name="pubName" type="java.lang.String">
<column name="pub_name" length="20" />
</property>
<set name="RReplies" inverse="true">
<key>
<column name="message_id" unique="true" />
</key>
<one-to-many class="com.accp.RReply" />
</set>
</class>
</hibernate-mapping>我是楼主
Transaction tr=session.beginTransaction();
getSession().save(transientInstance);
tr.commit();
Transaction tr=session.beginTransaction();
tr.commit();
save update delete必须要有事务
hibernate的事务直接调用jdbc的,默认关闭事务,需要手动打开关闭
或者采用spring的事务方式,用拦截器来实现
Hibernate: insert into accp.user (userName, passWord, id) values (?, ?, ?)
Hibernate: select message0_.id as id2_, message0_.user_id as user2_2_, message0_.context as context2_, message0_.title as title2_, message0_.pub_date as pub5_2_, message0_.pub_name as pub6_2_ from accp.message message0_
lixin
Hibernate: select max(id) from message
save successful
这是从登陆到发新帖的过程打印的信息,
登陆查询没问题!!
原来,IDE自己生成的save()没有封装事务,需要自己加进去
有朋友遇到过吗?求教