Searching this problem in the forum, this problem is repeated time by time. But it isn't solved actually, so I have to ask it for the N time. Frankly speaking, I'm a newbie to hibernate and jboss. But I must have this problem solved before the next step of my study. The problem is that the data isn't written to the database. Checking it in MySQL Administrator when the JBossAS is running, the rows of the table increased. But after closing the JBossAS, the rows of the table decreased. And when the JBossAS is on, select command can't select the rows not inserted actuallly.So I hope one could help me because of this problem have disturbed my study for weeks.
Test Environment:
JTA+Hibernate3.1.2+JBoss 4.03SP1
Mapping documents:
Code:
<?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">
<hibernate-configuration>
<session-factory name="SessionFactory">
<property name="hibernate.cglib.use_reflection_optimizer">true</property>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.password">30b12a87</property>
<property name="hibernate.connection.url">jdbc:mysql:///kdc</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.current_session_context_class">jta</property>
<property name="hibernate.debug">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.jta.UserTransaction">UserTransaction</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
<mapping resource="com/kdccn/general/entity/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
Codes in JSP for test:Code:
<%
UserTransaction tx=(UserTransaction)new InitialContext().lookup("UserTransaction");
%>
<%=(tx!=null)%>
<%
Configuration c=new Configuration().configure();
org.hibernate.SessionFactory sf=c.buildSessionFactory();
org.hibernate.Session s=sf.openSession();
tx.begin();
User user=new User();
user.setUsername("Test");
user.setPassword("Try");
sf.getCurrentSession().save(user);
sf.getCurrentSession().flush();
s.close();
tx.commit();
%>
<%=user.getId()%>