glassfish中使用hibernate jta事务管理 如题,,如何在glassfish中使用hibernate jta事务控制呢?我搞了半天了,不报错,但是就是插不了数据库 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个跟用哪个服务器没有关系的,八成是你配置搞错了,或者说sql语句没有提交惹得祸 配置代码和java代码如下,帮忙看看呢:<?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="connection.username">root</property> <property name="connection.url"> jdbc:mysql://localhost/soundcard </property> <property name="dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="myeclipse.connection.profile">mysql</property> <property name="connection.password">root</property> <property name="connection.driver_class"> com.mysql.jdbc.Driver </property> <property name="hibernate.transaction.manager_lookup_class"> org.hibernate.transaction.SunONETransactionManagerLookup </property> <property name="hibernate.current_session_context_class">org.hibernate.context.JTASessionContext</property> <property name="jta.UserTransaction">java:comp/UserTransaction</property> <property name="hibernate.transaction.factory_class"> org.hibernate.transaction.JTATransactionFactory </property> <property name="show_sql">true</property> <!-- --> <mapping resource="com/soundcard/bean/Role.hbm.xml" /> <mapping resource="com/soundcard/bean/Log.hbm.xml" /> <mapping resource="com/soundcard/bean/Communication.hbm.xml" /> <mapping resource="com/soundcard/bean/User.hbm.xml" /> <mapping resource="com/soundcard/bean/Permission.hbm.xml" /> <mapping resource="com/soundcard/bean/UserRole.hbm.xml" /> <mapping resource="com/soundcard/bean/Blacklist.hbm.xml" /> <mapping resource="com/soundcard/bean/RolePermission.hbm.xml" /> </session-factory></hibernate-configuration>User user = new User(); user.setUserid(userid); user.setPassword(Utils.toMD5Normal(password)); user.setName(username); user.setPhone(phone); UserRoleId userRoleId = new UserRoleId(); userRoleId.setRoleid(roleid); userRoleId.setUserid(userid); UserRole userRole = new UserRole(); userRole.setId(userRoleId); UserTransaction tx = null; try { tx = (UserTransaction)new InitialContext().lookup("java:comp/UserTransaction"); } catch (NamingException e) { e.printStackTrace(); } try { tx.begin(); } catch (NotSupportedException e1) { e1.printStackTrace(); } catch (SystemException e1) { e1.printStackTrace(); } IUserDao userDao = new UserDAO(); try { userDao.save(user); }catch(Exception e) { try { tx.rollback(); } catch(Exception re) { re.printStackTrace(); } } IUserRoleDao userRoleDao = new UserRoleDAO(); try { userRoleDao.save(userRole); } catch(Exception e) { try { tx.rollback(); } catch(Exception re) { re.printStackTrace(); } } try { tx.commit(); } catch (Exception e) { e.printStackTrace(); } 运行以后SQL语句能在服务器日志上显示出来的,但是就是插不了数据库 请教高手,JSP关于自定义标签 高手们进来看看!!! Winmerge 如何清晰对比代码顺序混乱问题? json 的可靠性问题 java发送邮件出现问题 如何搭建一个开发EJB环境! 紧急提问。(无法解析格式不规范的HTML文件)怎么解决?在线等待 请前辈们指教 easy 100分 求JAVA编程规范 java 等待进度条 could not find PropertyAccessor class: method是一个什么错误?怎么解决?
<!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/soundcard
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">mysql</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.transaction.manager_lookup_class">
org.hibernate.transaction.SunONETransactionManagerLookup
</property>
<property name="hibernate.current_session_context_class">org.hibernate.context.JTASessionContext</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="show_sql">true</property>
<!--
-->
<mapping resource="com/soundcard/bean/Role.hbm.xml" />
<mapping resource="com/soundcard/bean/Log.hbm.xml" />
<mapping resource="com/soundcard/bean/Communication.hbm.xml" />
<mapping resource="com/soundcard/bean/User.hbm.xml" />
<mapping resource="com/soundcard/bean/Permission.hbm.xml" />
<mapping resource="com/soundcard/bean/UserRole.hbm.xml" />
<mapping resource="com/soundcard/bean/Blacklist.hbm.xml" />
<mapping resource="com/soundcard/bean/RolePermission.hbm.xml" /> </session-factory></hibernate-configuration>
User user = new User();
user.setUserid(userid);
user.setPassword(Utils.toMD5Normal(password));
user.setName(username);
user.setPhone(phone);
UserRoleId userRoleId = new UserRoleId();
userRoleId.setRoleid(roleid);
userRoleId.setUserid(userid);
UserRole userRole = new UserRole();
userRole.setId(userRoleId);
UserTransaction tx = null;
try {
tx = (UserTransaction)new InitialContext().lookup("java:comp/UserTransaction");
} catch (NamingException e) {
e.printStackTrace();
}
try {
tx.begin();
} catch (NotSupportedException e1) {
e1.printStackTrace();
} catch (SystemException e1) {
e1.printStackTrace();
}
IUserDao userDao = new UserDAO();
try {
userDao.save(user);
}catch(Exception e) {
try {
tx.rollback();
} catch(Exception re) {
re.printStackTrace();
}
}
IUserRoleDao userRoleDao = new UserRoleDAO();
try {
userRoleDao.save(userRole);
} catch(Exception e) {
try {
tx.rollback();
} catch(Exception re) {
re.printStackTrace();
}
}
try {
tx.commit();
} catch (Exception e) {
e.printStackTrace();
}