-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem with saveOrUpdate
PostPosted: Fri Mar 20, 2009 2:31 am 
Newbie

Joined: Fri Mar 13, 2009 4:08 am
Posts: 9
Hi,

I'm implementing export and import functionality in my application. First the user will export all the data from database to the excel sheet and then he'll add (or) update any row or column in the excel sheet. For this I'm using saveOrUpdate method of Hibernate. But I'm getting error "Duplicate entry for Tag_Number (ofcourse its unique)". But I think this should be handled by Hibernate.

Do I need to add any attribute in my xml file, mapped with the table? Please help me.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 20, 2009 4:41 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
Can you post mapping file and SQL query for that table?

_________________
Thx,
Murugesan.
Web: http://www.murugesanpitchandi.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 20, 2009 7:06 am 
Newbie

Joined: Fri Mar 13, 2009 4:08 am
Posts: 9
Mapping file:

<hibernate-mapping default-access="field" >
<class name="com.analytica.net.badge.Badge" table="bm_badge_master">
<id name="id" column="BM_BADGE_ID" >
<generator class="native" />
</id>
<property name="tag" column="BM_BADGE_TAG_ID"/>
<property name="category" column="BM_BADGE_TYPE_ID"/>
<property name="assigned" column="BM_BADGE_ASSIGNED"/>
<property name="icon" column="BM_BADGE_ICONPATH"/>
<property name="at" column="BM_BADGE_AT"/>
<property name="pic" column="BM_BADGE_PIC"/>
<property name="created" column="BM_CREATED_ON"/>
<property name="quantity" column="BM_QUANTITY"/>
<property name="status" column="BM_BADGE_STATUS"/>
<property name="lastupdated" column="BM_LAST_UPDATED"/>
<property name="grnid" column="BM_BADGE_GRN_ID"/>

<!-- Badge Param 1 to 15 -->
<property name="param1" column="BM_BADGE_PARAM1" />
<property name="param2" column="BM_BADGE_PARAM2" />
<property name="param3" column="BM_BADGE_PARAM3" />
<property name="param4" column="BM_BADGE_PARAM4" />
<property name="param5" column="BM_BADGE_PARAM5" />
<property name="param6" column="BM_BADGE_PARAM6" />
<property name="param7" column="BM_BADGE_PARAM7" />
<property name="param8" column="BM_BADGE_PARAM8" />
<property name="param9" column="BM_BADGE_PARAM9" />
<property name="param10" column="BM_BADGE_PARAM10" />
<property name="param11" column="BM_BADGE_PARAM11" />
<property name="param12" column="BM_BADGE_PARAM12" />
<property name="param13" column="BM_BADGE_PARAM13" />
<property name="param14" column="BM_BADGE_PARAM14" />
<property name="param15" column="BM_BADGE_PARAM15" />
</class>
</hibernate-mapping>

And executing query like this :

SessionFactory factory = getHibernateTemplate().getSessionFactory();
Session session = factory.openSession();
Transaction tx = session.beginTransaction();

try {
for (int i = 0; i < badge.size(); i++) {
Badge b = new Badge(); //Creating Badge Object corresponding the mapping provided above
b.tag = badge.get("tag");
b.category = badge.get("category");
b.at = badge.get("at");
b.assigned = badge.get("assigned");
b.icon = badge.get("icon");
b.pic = badge.get("pic");
b.quantity = badge.get("quantity");
b.grnid = badge.get("grnid");
b.param1 = badge.get("param1");
b.param2 = badge.get("param2");
b.param3 = badge.get("param3");
b.param4 = badge.get("param4");
b.param5 = badge.get("param5");
b.param6 = badge.get("param6");
b.param7 = badge.get("param7");
b.param8 = badge.get("param8");
b.param9 = badge.get("param9");
b.param10 = badge.get("param10");
b.param11 = badge.get("param11");
b.param12 = badge.get("param12");
b.param13 = badge.get("param13");
b.param14 = badge.get("param14");
b.param15 = badge.get("param15");
b.status = badge.get("status");
b.created = new Date();
session.saveOrUpdate(b);

}
tx.commit();
} catch (Exception e) {
tx.rollback();
}
[/b][/u]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 20, 2009 8:23 am 
Beginner
Beginner

Joined: Wed Oct 03, 2007 4:10 am
Posts: 46
First of all I think you should used setters for bean properties and not field access.

Second you should modify the log4j.xml in order to log more information
(the sql and parameters)

<category name="org.hibernate.type">
<priority value="trace"/>
</category>

<!--category name="org.hibernate.SQL">
<priority value="debug"/>
</category>

And third
The duplicate values exception i think it comes from database. Hibernate doesn't verify this sort of things. So you have to check the constraints defined in database.

Good luck.


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