-->
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.  [ 6 posts ] 
Author Message
 Post subject: Oracle data insertion problem.
PostPosted: Thu Nov 20, 2003 5:53 am 
Newbie

Joined: Mon Nov 17, 2003 2:43 am
Posts: 10
Hi,
I am not aware due to waht reason I am not able to insert any value for oen of my table. The mapping file is as follows:

Code:
<hibernate-mapping>
    <class name="com.dc.teldirectory.trans.TransRequestBean" table="TBL_TRANS_REQUEST">
        <composite-id>
            <key-property column="LANG_ID" length="2" name="langId" type="string"/>
            <key-property column="LANG_STRING" length="100" name="langString" type="string"/>
        </composite-id>
        <property column="REQ_DATE" length="7" name="reqDate" type="date"/>
    </class>
</hibernate-mapping>


The code that I am running is as follows:

Code:
Session session = null ;
        TransRequestBean trBean = new TransRequestBean();
        try{
            session = sFactory.openSession();           
            trBean.setLangId(langId);
            trBean.setLangString(langString);
            trBean.setReqDate(new java.util.Date());                       
            session.saveOrUpdate(trBean); 
            System.out.println("Object TransRequestBean saved");
        }
        catch(HibernateException he){
                  }       
        catch(Exception e){
                   }
        finally{
            session.close();
            session = null;
            trBean = null;
        }   


Problem is the statements till the SOP "Object TransRequestBean saved" are executed but the data is not inserted in the database. The output from the log is as follows:
Code:
20 Nov 2003 13:16:42 DEBUG [Servlet.Engine.Transports:39] impl.SessionImpl - opened session
20 Nov 2003 13:16:42 DEBUG [Servlet.Engine.Transports:39] engine.Cascades - unsaved-value strategy NONE
20 Nov 2003 13:16:42 DEBUG [Servlet.Engine.Transports:39] impl.SessionImpl - saveOrUpdate() previously saved instance with id: com.dc.teldirectory.trans.TransRequestBean@881e0c6[langId=HI,langString=Agyat]
20 Nov 2003 13:16:42 DEBUG [Servlet.Engine.Transports:39] impl.SessionImpl - updating [com.dc.teldirectory.trans.TransRequestBean#com.dc.teldirectory.trans.TransRequestBean@881e0c6[langId=HI,langString=Agyat]]
20 Nov 2003 13:16:42 DEBUG [Servlet.Engine.Transports:39] impl.SessionImpl - closing session


The problems I guess are:
1. Why the log says: previously saved instance with id: com.dc.teldirectory.trans.TransRequestBean@881e0c6[langId=HI,langString=Agyat] hence updating while the table is absolutely empty?
2. The ReqDate column in my table is of type Date, the bean class has a corresponding Date attribute. Is the problem due to isertion of the date returned by the Date returned by the new Date()?
3. I tried not inserting the Date (null is allowed) and only the langid/text the combination of both is proimary key, but still data was not inserted. I am not getting any error out of the catch blocks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 5:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Set unsaved-value="none". This is a FAQ.


Top
 Profile  
 
 Post subject: The problem persists
PostPosted: Thu Nov 20, 2003 7:28 am 
Newbie

Joined: Mon Nov 17, 2003 2:43 am
Posts: 10
I am not sure and I have just started with hibernate but the hibernate_refrence says that the attribute unsaved-value of composite-id element is optional and defaults to none. Even in the log it has written "20 Nov 2003 16:44:15 DEBUG [Servlet.Engine.Transports:47] engine.Cascades - unsaved-value strategy NONE".

My mapping file now looks as follows and I am not able to insert the values even now.
Code:
<hibernate-mapping>
    <class name="com.reliance.teldirectory.trans.TransRequestBean" table="TBL_TRANS_REQUEST">
        <composite-id unsaved-value="none">
            <key-property column="LANG_ID" length="2" name="langId" type="string"/>
            <key-property column="LANG_STRING" length="100" name="langString" type="string"/>
        </composite-id>
        <property column="REQ_DATE" length="7" name="reqDate" type="date"/>
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 7:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ack! I mis-spoke:

set unsaved-value="any"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 7:51 am 
Newbie

Joined: Mon Nov 17, 2003 2:43 am
Posts: 10
I got the foolowing and still no insert
Code:
20 Nov 2003 17:05:22 DEBUG [Servlet.Engine.Transports:10] impl.SessionImpl - opened session
20 Nov 2003 17:05:22 DEBUG [Servlet.Engine.Transports:10] engine.Cascades - unsaved-value strategy ANY
20 Nov 2003 17:05:22 DEBUG [Servlet.Engine.Transports:10] impl.SessionImpl - saveOrUpdate() unsaved instance with id: com.reliance.teldirectory.trans.TransRequestBean@4e34e0db[langId=HI,langString=Agyat]
20 Nov 2003 17:05:22 DEBUG [Servlet.Engine.Transports:10] impl.SessionImpl - saving [com.reliance.teldirectory.trans.TransRequestBean#com.reliance.teldirectory.trans.TransRequestBean@4e34e0db[langId=HI,langString=Agyat]]
20 Nov 2003 17:05:22 DEBUG [Servlet.Engine.Transports:10] impl.SessionImpl - closing session

I am not sure whether it is due to the date column. Because even if I try inserting only the composite key values (not the date) it still does not insert.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 8:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You forgot to flush() the session.

Looks like you also don't commit the JDBC transaction.

This is the first item in the FAQ.


Please go and read the FAQ from top to bottom, TIA.


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