-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate transaction duplicate problem
PostPosted: Sat Aug 01, 2009 6:26 am 
Newbie

Joined: Sat Jul 11, 2009 2:46 am
Posts: 7
Hi every one, I want update some of my table in database and want all of these work do in 1 transaction, first of all I delete some entry in branchbuildin(Table) and Insert new one after this action The problem occurred when I insert and entry with same buildingname and branch_fk (be cause I have this constraint on this table ( uniqueConstraints={@UniqueConstraint(columnNames={"buildingname","branch_fk"})})) but when I don't use hibernate session and use normal JDBC transaction I don't have these problem.

Code:
List<Integer> allBranchBuilding = branchBuildingDao.getAllBranchBuildingID(pkId, sess);
            for (Integer integer : allBranchBuilding) {
                branchBuildingDao.delete(integer, sess); // delete kardane tamame BranchBuilding ha va tel haie aanha
            }

            Address myAdr = new Address();
            setAddress(myAdr, centralFlag, city, latit, longit, mainstreet, remainAdr, state);
            BranchBuildingEntity bbe = new BranchBuildingEntity();
            setBranchBuildingEntity(bbe, be, myAdr, city, centralFlag, latit, longit, mainstreet, buildingName, remainAdr, state, des);
            branchBuildingDao.save(bbe, sess);//Exception Occurred

I get my session at the first of Method:
Code:
  Session sess = null;
        sess = HibernateUtil.getSession();
        Transaction tx = sess.beginTransaction();

_________________
-*-*-*-*-*
[Am1rr3zA]


Top
 Profile  
 
 Post subject: Re: Hibernate transaction duplicate problem
PostPosted: Wed Aug 05, 2009 8:58 am 
Newbie

Joined: Sat Jul 11, 2009 2:46 am
Posts: 7
I solve My problem by write sess.flush(); before the line of .save()

_________________
-*-*-*-*-*
[Am1rr3zA]


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