-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 
Author Message
 Post subject: JTA+Hibernate3.1.2+JBossAS 4.03 not writing data to database
PostPosted: Sat Mar 18, 2006 4:07 am 
Beginner
Beginner

Joined: Sun Mar 05, 2006 12:16 am
Posts: 31
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()%>


Last edited by Seto on Sat Mar 18, 2006 6:15 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 18, 2006 4:23 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Quote:
select command can't select the rows not inserted actuallly

wtf?

Be more specific / accurate.

Do you maybe have a hbm2dll 'create_drop'?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 18, 2006 4:39 am 
Beginner
Beginner

Joined: Sun Mar 05, 2006 12:16 am
Posts: 31
I means that I used "select * from user" sql command in mysql administrator. But it return no result. But the rows of the table had increased. So I tink that it's the problem of no writing data in the database. I think it seems that the transaction isn't commited actually. So I hope you can help me with this problem


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 18, 2006 4:53 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Debug, debug and debug.
Turn on sql log.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 18, 2006 5:01 am 
Beginner
Beginner

Joined: Sun Mar 05, 2006 12:16 am
Posts: 31
16:59:24,718 INFO [STDOUT] Hibernate: insert into user (username, password) val
ues (?, ?)

Can you login the MSN Messenger? Maybe that can make my asking you for help more easily. My MSN is RealSetoKaiba@msn.com


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 19, 2006 2:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Close the session after the transaction commit.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 19, 2006 3:19 am 
Beginner
Beginner

Joined: Sun Mar 05, 2006 12:16 am
Posts: 31
Please see clearly. I'm using JTA. It's no matter to close the session before the transaction commits. I just tried as you said. It couldn't work, either


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 19, 2006 3:56 am 
Beginner
Beginner

Joined: Sun Mar 05, 2006 12:16 am
Posts: 31
Er...I want to ask whether there are some settings neccessary to set in spite of the cfg.xml. Does the JBossAS need some settings? I haven't done any settings else despite of the settings list at the thread. Can someone give me a detail settings for JBoss use JTA to manage the transaction. It's lack of detail in the documentations.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 19, 2006 4:52 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Try using a JBoss configured datasource.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 6:27 am 
Beginner
Beginner

Joined: Fri Oct 28, 2005 7:11 am
Posts: 20
I remember that I had similar case. I think I added one of the line:
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.connection.release_mode">after_statement</property>
<property name="hibernate.transaction.auto_close_session">true</property>
and it helped.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 12:03 pm 
Beginner
Beginner

Joined: Sun Mar 05, 2006 12:16 am
Posts: 31
Not work. Could you give me your sample?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 8:59 am 
Newbie

Joined: Thu Mar 09, 2006 7:02 am
Posts: 6
Location: Kiev
I had the same problem. Looks like save(insert to table) doesn't works with JTA transactions : Hibernate + JOTM + Tomcat.

But then I configured Datasource in Tomcat and it works !!!!
remove this:

<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>

put this:

<property name="connection.datasource">java:comp/env/jdbc/rzbrss_oratgr_xa</property>

_________________
Oleksandr Markelov
SCJP, SCWCD, SCBCD


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.