-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate transaction problems
PostPosted: Sat Jul 26, 2008 9:39 am 
Newbie

Joined: Sun Jun 29, 2008 4:42 pm
Posts: 3
Hi i have a problems with hibernate, i think that there are problems with transactions..i have already read this http://hibernate.org/42.html but it did not helped me..
why when i do a statement as a insert it does not work and i get a java null pointer exception?
this is the java code
Code:
            Session session = HibernateUtil.getSessionFactory().openSession();

            Transaction tx = session.getTransaction();
             tx.commit();
            session.save(a_user_object);
            session.close();


this is the log
Code:
....
15:25:40,125  INFO NamingHelper:26 - JNDI InitialContext properties:{}
15:25:40,125  INFO DatasourceConnectionProvider:61 - Using datasource: java:/comp/env/database
15:25:40,828  INFO SettingsFactory:89 - RDBMS: MySQL, version: 5.0.51b-community-nt
15:25:40,828  INFO SettingsFactory:90 - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.5 ( Revision: ${svn.Revision} )
15:25:40,906  INFO Dialect:152 - Using dialect: org.hibernate.dialect.MySQLDialect
15:25:40,906  INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
15:25:40,921  INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
15:25:40,921  INFO SettingsFactory:143 - Automatic flush during beforeCompletion(): disabled
15:25:40,921  INFO SettingsFactory:147 - Automatic session close at end of transaction: disabled
15:25:41,000  INFO SettingsFactory:154 - JDBC batch size: 15
15:25:41,000  INFO SettingsFactory:157 - JDBC batch updates for versioned data: disabled
15:25:41,015  INFO SettingsFactory:162 - Scrollable result sets: enabled
15:25:41,015  INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): enabled
15:25:41,015  INFO SettingsFactory:178 - Connection release mode: auto
15:25:41,015  INFO SettingsFactory:202 - Maximum outer join fetch depth: 2
15:25:41,015  INFO SettingsFactory:205 - Default batch fetch size: 1
15:25:41,109  INFO SettingsFactory:209 - Generate SQL with comments: disabled
15:25:41,109  INFO SettingsFactory:213 - Order SQL updates by primary key: disabled
15:25:41,109  INFO SettingsFactory:217 - Order SQL inserts for batching: disabled
15:25:41,109  INFO SettingsFactory:386 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
15:25:41,125  INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
15:25:41,125  INFO SettingsFactory:225 - Query language substitutions: {}
15:25:41,203  INFO SettingsFactory:230 - JPA-QL strict compliance: disabled
15:25:41,203  INFO SettingsFactory:235 - Second-level cache: enabled
15:25:41,203  INFO SettingsFactory:239 - Query cache: disabled
15:25:41,203  INFO SettingsFactory:373 - Cache provider: org.hibernate.cache.NoCacheProvider
15:25:41,203  INFO SettingsFactory:254 - Optimize cache for minimal puts: disabled
15:25:41,203  INFO SettingsFactory:263 - Structured second-level cache entries: disabled
15:25:41,218  INFO SettingsFactory:283 - Echoing all SQL to stdout
15:25:41,296  INFO SettingsFactory:290 - Statistics: disabled
15:25:41,296  INFO SettingsFactory:294 - Deleted entity synthetic identifier rollback: disabled
15:25:41,312  INFO SettingsFactory:309 - Default entity-mode: pojo
15:25:41,312  INFO SettingsFactory:313 - Named query checking : enabled
15:25:41,453  INFO SessionFactoryImpl:161 - building session factory
15:25:42,203  INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
Hibernate: insert into tblusers (username, pw, email, role, active) values (?, ?, ?, ?, ?)
15:25:42,531 ERROR UserManager:54 - java.lang.NullPointerException

i don't understand why it doesn't work..
thanks


Top
 Profile  
 
 Post subject: Resolved!
PostPosted: Sat Jul 26, 2008 10:48 am 
Newbie

Joined: Sun Jun 29, 2008 4:42 pm
Posts: 3
I have resolved
I have begin the transaction with tx.begin() after get the transaction and then commit works fine!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 26, 2008 8:32 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Yes, this bites many newbies.

Thanks for updating your post!

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.