-->
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.  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Hibernate.sar/JBoss: Values not saved to DB
PostPosted: Thu Feb 19, 2004 12:25 pm 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
Hi,

i have a strange problem with JBoss&hibernate as a .sar: I have a SessionBean, that has to persist classes into the db, using the Hibernate-Sessions fetched from the .sar - I get no exceptions neither on openSession, beginTransaction, nor on tx.commit() - but the value is never saved to the Database - is there anything else I am missing here???!

And what happens if i just want to join a transaction - I see from the logs, that hibernate starts a user_transaction, when i sess.beginTransaction(); - what do i have to do when i just want to join a container-transaction?! Just skip the .beginTransaction/.commit()?!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 12:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Have you set the transaction-management attributes in the sar correctly, like this:

Code:
<attribute name="UserTransactionName">UserTransaction</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>

You are using a recent version of Hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 12:44 pm 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
yes, i have all these attributes from the tutorial set up. Hibernate Version is 2.0.3 - Is it a good Idea to switch to 2.1.2?!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 12:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Probably, try it out ...


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 22, 2004 11:50 pm 
Newbie

Joined: Mon Nov 17, 2003 1:51 am
Posts: 16
I am using hibernate 2.1.2, the problem was tested with both jboss 3.2.3 and jboss cvs (3.2.4RC1)

I am having the same problem, basically the data is not being persisted.

Here is my jboss-service.xml

Code:
<server>
   <mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=Hibernate">
       <depends>jboss.jca:service=RARDeployer</depends>
       <attribute name="MapResources">...</attribute>
       <attribute name="JndiName">java:/HibernateFactory</attribute>
       <attribute name="Datasource">java:/PostgresDS</attribute>
       <attribute name="Dialect">net.sf.hibernate.dialect.PostgreSQLDialect</attribute>
       <attribute name="UseOuterJoin">true</attribute>
       <attribute name="ShowSql">true</attribute>
       <attribute name="UserTransactionName">UserTransaction</attribute>
       <attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
       <attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
   </mbean>

   <depends>jboss.jca:service=LocalTxCM,name=PostgresDS</depends>

<attribute name="CacheProvider">net.sf.ehcache.hibernate.Provider</attribute>

</server>



Console Output

Code:
[STDOUT] Feb 22, 2004 7:20:22 PM com.fudosan.infrastructure.persistence.hibernate.HibernateAgentDAO create
INFO: Created agent: 2062
19:20:22,415 INFO  [JtaTransactionManager] Initiating transaction commit




The file log
Code:
2004-02-22 18:58:32,274 DEBUG [org.springframework.transaction.interceptor.TransactionInterceptor] Getting transaction for method 'create' in class [com.fudosan.infrastructure.persistence.AgentDAO]
2004-02-22 18:58:32,274 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] Using transaction object [org.jboss.tm.usertx.client.ServerVMClientUserTransaction@2982bf]
2004-02-22 18:58:32,274 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] Creating new transaction
2004-02-22 18:58:32,274 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] Beginning JTA transaction [org.jboss.tm.usertx.client.ServerVMClientUserTransaction@2982bf]
2004-02-22 18:58:32,275 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] Initializing transaction synchronization
2004-02-22 18:58:32,279 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] Retrieved value [org.springframework.orm.hibernate.SessionHolder@3f4f44] for key [net.sf.hibernate.impl.SessionFactoryImpl@39029b] bound to thread [http8080-Processor25]
2004-02-22 18:58:32,279 DEBUG [net.sf.hibernate.impl.BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
2004-02-22 18:58:32,283 DEBUG [net.sf.hibernate.SQL] select nextval ('hibernate_sequence')
2004-02-22 18:58:32,283 INFO  [STDOUT] Hibernate: select nextval ('hibernate_sequence')
2004-02-22 18:58:32,285 DEBUG [net.sf.hibernate.impl.BatcherImpl] preparing statement
2004-02-22 18:58:32,288 DEBUG [net.sf.hibernate.id.SequenceGenerator] Sequence identifier generated: 206
2004-02-22 18:58:32,288 DEBUG [net.sf.hibernate.impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
2004-02-22 18:58:32,288 DEBUG [net.sf.hibernate.impl.BatcherImpl] closing statement
2004-02-22 18:58:32,288 DEBUG [net.sf.hibernate.id.SequenceHiLoGenerator] new hi value: 206
2004-02-22 18:58:32,288 DEBUG [net.sf.hibernate.impl.SessionImpl] generated identifier: 2061
2004-02-22 18:58:32,288 DEBUG [net.sf.hibernate.impl.SessionImpl] saving [com.fudosan.domain.realestate.Agent#2061]
2004-02-22 18:58:32,288 DEBUG [net.sf.hibernate.engine.Cascades] processing cascades for: com.fudosan.domain.realestate.Agent
2004-02-22 18:58:32,288 DEBUG [net.sf.hibernate.engine.Cascades] cascading to saveOrUpdate()
2004-02-22 18:58:32,289 DEBUG [net.sf.hibernate.impl.SessionImpl] saveOrUpdate() unsaved instance
2004-02-22 18:58:32,289 DEBUG [net.sf.hibernate.impl.BatcherImpl] about to open: 0 open PreparedStatements, 0 open ResultSets
2004-02-22 18:58:32,289 DEBUG [net.sf.hibernate.SQL] select nextval ('hibernate_sequence')
2004-02-22 18:58:32,289 INFO  [STDOUT] Hibernate: select nextval ('hibernate_sequence')
2004-02-22 18:58:32,293 DEBUG [net.sf.hibernate.impl.BatcherImpl] preparing statement
2004-02-22 18:58:32,305 DEBUG [net.sf.hibernate.id.SequenceGenerator] Sequence identifier generated: 207
2004-02-22 18:58:32,306 DEBUG [net.sf.hibernate.impl.BatcherImpl] done closing: 0 open PreparedStatements, 0 open ResultSets
2004-02-22 18:58:32,306 DEBUG [net.sf.hibernate.impl.BatcherImpl] closing statement
2004-02-22 18:58:32,306 DEBUG [net.sf.hibernate.id.SequenceHiLoGenerator] new hi value: 207
2004-02-22 18:58:32,306 DEBUG [net.sf.hibernate.impl.SessionImpl] generated identifier: 2071
2004-02-22 18:58:32,306 DEBUG [net.sf.hibernate.impl.SessionImpl] saving [com.fudosan.domain.realestate.Office#2071]
2004-02-22 18:58:32,306 DEBUG [net.sf.hibernate.engine.Cascades] processing cascades for: com.fudosan.domain.realestate.Office
2004-02-22 18:58:32,306 DEBUG [net.sf.hibernate.engine.Cascades] done processing cascades for: com.fudosan.domain.realestate.Office
2004-02-22 18:58:32,306 DEBUG [net.sf.hibernate.engine.Cascades] processing cascades for: com.fudosan.domain.realestate.Office
2004-02-22 18:58:32,306 DEBUG [net.sf.hibernate.engine.Cascades] cascading to collection: com.fudosan.domain.realestate.Office.agents
2004-02-22 18:58:32,306 DEBUG [net.sf.hibernate.engine.Cascades] cascading to collection: com.fudosan.domain.realestate.Office.properties
2004-02-22 18:58:32,306 DEBUG [net.sf.hibernate.engine.Cascades] done processing cascades for: com.fudosan.domain.realestate.Office
2004-02-22 18:58:32,306 DEBUG [net.sf.hibernate.engine.Cascades] done processing cascades for: com.fudosan.domain.realestate.Agent
2004-02-22 18:58:32,307 DEBUG [net.sf.hibernate.engine.Cascades] processing cascades for: com.fudosan.domain.realestate.Agent
2004-02-22 18:58:32,307 DEBUG [net.sf.hibernate.engine.Cascades] cascading to collection: com.fudosan.domain.realestate.Agent.listings
2004-02-22 18:58:32,307 DEBUG [net.sf.hibernate.engine.Cascades] done processing cascades for: com.fudosan.domain.realestate.Agent
2004-02-22 18:58:32,332 INFO  [STDOUT] Feb 22, 2004 6:58:32 PM com.fudosan.infrastructure.persistence.hibernate.HibernateAgentDAO create
INFO: Created agent: 2061
2004-02-22 18:58:32,333 DEBUG [org.springframework.transaction.interceptor.TransactionInterceptor] Invoking commit for transaction on method 'create' in class [com.fudosan.infrastructure.persistence.AgentDAO]
2004-02-22 18:58:32,333 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] Triggering beforeCommit synchronization
2004-02-22 18:58:32,333 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] Triggering beforeCompletion synchronization
2004-02-22 18:58:32,333 INFO  [org.springframework.transaction.jta.JtaTransactionManager] Initiating transaction commit
2004-02-22 18:58:32,333 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] Committing JTA transaction [org.jboss.tm.usertx.client.ServerVMClientUserTransaction@2982bf]
2004-02-22 18:58:32,333 DEBUG [net.sf.hibernate.engine.CacheSynchronization] transaction before completion callback
2004-02-22 18:58:32,365 DEBUG [net.sf.hibernate.engine.CacheSynchronization] transaction after completion callback, status: 3
2004-02-22 18:58:32,365 DEBUG [net.sf.hibernate.impl.SessionImpl] transaction completion
2004-02-22 18:58:32,365 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] Triggering afterCompletion synchronization
2004-02-22 18:58:32,366 DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] Clearing transaction synchronization




Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 6:00 pm 
Senior
Senior

Joined: Tue Nov 25, 2003 9:35 am
Posts: 194
Location: San Francisco
Completely weird. Have you asked any Spring/Hibernate folks about this one?

You have a buggy XDoclet template for the jboss-service.xml. The depends stuff is in the wrong place. See 66.html on the Hibernate web site for a fix.

Sherman


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 6:11 pm 
Newbie

Joined: Mon Nov 17, 2003 1:51 am
Posts: 16
I fixed xdoclet to generate a correct jboss-service.xml but my problem is not solved. I would try asking on the spring forum but the other person had the same problem and he's not using spring


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 6:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Pretty weird, because there actually IS a transaction committed entry in the log. Do you have SQL logging enabled? There are querys executed, aren't there?

Are you sure you are checking the database the datasource refers to? Are there any such errors you might have overlooked? :))


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 6:41 pm 
Newbie

Joined: Mon Nov 17, 2003 1:51 am
Posts: 16
Yes I have SQL logging enabled there is no [b] insert [b] below is the sql log
Code:
[STDOUT] Hibernate: select nextval ('hibernate_sequence')
14:05:20,729 INFO  [STDOUT] Hibernate: select nextval ('hibernate_sequence')
[quote]

I am sure the database is configured correctly because all the search and load operations work correctly with transactions it's only inserts that are not working.

I can't think of any error that i have overlooked, i have detailed postgresql logging that logs all database activity.  I looked at my application logs, hibernate logs and jboss logs and nothing suspecious.
It might be a problem related to spring framework. [/b][/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 6:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Probably you are just missing a session.flush() somewhere?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 6:49 pm 
Newbie

Joined: Mon Nov 17, 2003 1:51 am
Posts: 16
Well spring is supposed to handle hibernate sessions and flush them. I am gong to write some test code without using spring to determine if my problem is related to spring or jboss+hibernate.
thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 8:28 pm 
Newbie

Joined: Mon Nov 17, 2003 1:51 am
Posts: 16
Thanks to Juergen I was able to solve my problem. The session was not flushed because I was using OpenSessionInViewFilter.


Top
 Profile  
 
 Post subject: save vs. saveOrUpdate
PostPosted: Mon Mar 29, 2004 10:29 am 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
In the meantime, i managed to I solved my problem too: There seems to be either a bug or a misunderstanding in the api: If i use .save(Object obj), everything works as expected, but if i use saveOrUpdate(Object obj), the Object never shows up in the DB - i suspected, that it looks for a filled id and updates, if it is present, and else just does a normal save - at least that's what I suspected hibernate to do - is this wrong?!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 29, 2004 10:32 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Please read the documentation.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 10:07 am 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
I read the documentation, it says it saves or updates to the DB- but it does not save or update, at least not in a predicatable manner: I can now save an object, which has a one-one-mapping to a dependent object(mapped using cascade=all). Hibernate saves the Primary Object, but not the dependent one, even if I save the dependent Object manually. But Hibernate does not complain in any way, the only thing that looks strange is the id=0 returned from sess.save(dependentObject). I'm running Oracle and use generator class="native", which works fine for the Object, but not for the dependent one. Is there another error log somewhere?!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 21 posts ]  Go to page 1, 2  Next

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.