-->
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 saveOrUpdate method is not working as expected
PostPosted: Mon Jan 10, 2011 1:25 am 
Beginner
Beginner

Joined: Mon Sep 20, 2010 2:35 am
Posts: 20
Hi All,

learning Hibernate and its really making me crazy i am trying to persist an entity class along with its chilren and here is the method which is doing this for me
Code:
log.info("About to persist the given Entity instance");
        Session session=HibernateSessionFactory.getSessionfactory().openSession();
        Transaction tx=session.getTransaction();
        try{
            tx.begin();
            session.saveOrUpdate(entity);
            tx.commit();
        }
        catch(Exception e){
            tx.rollback();
        }
        finally{
            session.close();
        }
        return entity;
    }


everything seems ok and here is the console output i am totally clueless hibernate is not showing any exception nor its saving anything in the database
Code:
23:47:08,627  INFO GenericDAOImpl:172 - About to persist the given Entity instance
2011-01-09 23:47:08,627 [http-8080-3] INFO  com.raisonne.tr.dao.impl.GenericDAOImpl - About to persist the given Entity instance
9 Jan, 2011 11:47:08 PM org.hibernate.impl.SessionFactoryImpl close
INFO: closing
9 Jan, 2011 11:47:08 PM org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:mysql://localhost/travellingrants
9 Jan, 2011 11:47:08 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
9 Jan, 2011 11:47:08 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
9 Jan, 2011 11:47:08 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
9 Jan, 2011 11:47:08 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/travellingrants
9 Jan, 2011 11:47:08 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=root, password=****}
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: MySQL, version: 5.1.51-community
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.13 ( Revision: ${bzr.revision-id} )
9 Jan, 2011 11:47:08 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
9 Jan, 2011 11:47:08 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
9 Jan, 2011 11:47:08 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default schema: travellingrants
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: enabled
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
9 Jan, 2011 11:47:08 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory createRegionFactory
INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
9 Jan, 2011 11:47:08 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
9 Jan, 2011 11:47:08 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
9 Jan, 2011 11:47:08 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured




can any one having idea about hibernate suggest me what is wrong all i can see some suspicious lines of log entires
Code:
9 Jan, 2011 11:47:08 PM org.hibernate.impl.SessionFactoryImpl close
INFO: closing
9 Jan, 2011 11:47:08 PM org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:mysql://localhost/travellingrants


below are the mapping file entries from parents and child entities respectively

Code:
</property>
        <property name="longDescription" type="java.lang.String">
            <column name="LONGDESCRIPTION" />
        </property>

        <set name="airTransport" table="AIRTRANSPORT" inverse="true" lazy="true" cascade="save-update">
            <key>
                <column name="DESTINATIONID" />
            </key>
            <one-to-many class="com.raisonne.tr.model.destination.destinationattributes.AirTransport" />
        </set>
        <set name="roadTransport" table="ROADTRANSPORT" inverse="true" lazy="true" cascade="save-update">
            <key>
                <column name="DESTINATIONID" />
            </key>
            <one-to-many class="com.raisonne.tr.model.destination.destinationattributes.RoadTransport" />
        </set>
        <set name="trainTransport" table="TRAINTRANSPORT" inverse="true" lazy="true" cascade="save-update">
            <key>
                <column name="DESTINATIONID" />
            </key>
            <one-to-many class="com.raisonne.tr.model.destination.destinationattributes.TrainTransport" />
        </set>

        <set name="emergencyContact" table="EMERGENCYCONTACT" inverse="true" lazy="true" cascade="save-update">
            <key>
                <column name="DESTINATIONID" />
            </key>
            <one-to-many class="com.raisonne.tr.model.destination.destinationattributes.EmergencyContact" />
        </set>

        <set name="placesToVisit" table="PLACETOVISIT" inverse="true" lazy="true" cascade="save-update">
            <key>
                <column name="DESTINATIONID" />
            </key>
            <one-to-many class="com.raisonne.tr.model.destination.destinationattributes.PlaceToVisit" />
        </set>
        <set name="news" table="NEWS" inverse="true" lazy="true" cascade="save-update">
            <key>
                <column name="DESTINATIONID" />
            </key>
            <one-to-many class="com.raisonne.tr.model.news.News" />
        </set>
        <set name="userComments" table="USERCOMMENT" inverse="true" lazy="true" cascade="save-update">
            <key>
                <column name="DESTINATIONID" />
            </key>
            <one-to-many class="com.raisonne.tr.model.user.UserComment" />
        </set>
        <set name="address" table="BASICADDRESS" inverse="true" lazy="true" cascade="save-update">
            <key>
                <column name="DESTINATIONID" />
            </key>
            <one-to-many class="com.raisonne.tr.model.address.BasicAddress" />
        </set>
        <set name="categories" table="CATEGORY" inverse="true" lazy="true" cascade="save-update">
            <key>
                <column name="DESTINATIONID" />
            </key>
            <one-to-many class="com.raisonne.tr.model.category.Category" />
        </set>
    </class>
</hibernate-mapping>


Child entity
Code:
<hibernate-mapping>
    <class name="com.raisonne.tr.model.destination.destinationattributes.PlaceToVisit" table="PLACETOVISIT">
        <id name="uuid" type="java.lang.String">
            <column name="UUID" />
            <generator class="uuid" />
        </id>
        <property name="name" type="java.lang.String">
            <column name="NAME" />
        </property>
        <many-to-one name="destination" class="com.raisonne.tr.model.destination.Destination" fetch="join">
            <column name="DESTINATION" />
        </many-to-one>
        </class>
</hibernate-mapping>


i am unable to find what exactly is wrong since neither hibernate issuing any save or update command nor any error/exception on the console.

any help in this regard is much appreciated


Top
 Profile  
 
 Post subject: Re: Hibernate saveOrUpdate method is not working as expected
PostPosted: Mon Jan 10, 2011 2:51 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
INFO-level logging is not enough to see what is going on. Change your logging level to DEBUG (and be prepared for a lot of output).

Maybe you'll also see something if you actually print out the stacktrace in the catch clause:

Code:
catch(Exception e){
    e.printStackTrace();
    tx.rollback();
}


Top
 Profile  
 
 Post subject: Re: Hibernate saveOrUpdate method is not working as expected
PostPosted: Mon Jan 10, 2011 2:55 am 
Beginner
Beginner

Joined: Mon Sep 20, 2010 2:35 am
Posts: 20
Nordborg,

Agree will do it and if not able to find any clue still will update the post.
Thanks for the pointer..


-Best
Umesh


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.