-->
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: For each and random insert in data base.
PostPosted: Tue Feb 01, 2011 8:31 pm 
Newbie

Joined: Tue Feb 01, 2011 8:17 pm
Posts: 7
Hi,

I have a trouble with the session.save..
I have a list of object Flight and each Flight have a list of FlightSegment.
The joke is, if i break my "loop for" at the first run, i refind my Flight and his 2 FlightSegment properly register in the database.
If i i dont break i have the 3 Flight (of Flist) but i miss the second FlightSegment of he first Flight...
And the print show me properly all the FlightSegment , in all the case.

The "for each" going too fast for hibernate insert ? Like the instance of v from the first turn of loop erase the v instance of the next turn ????

Code:
for(Flight v : Flist){
    tx = session.beginTransaction();
    for (FlightSegment fg : v.getListFlightSegment()){
   System.out.println(fg.getStartAirp()+"-"+fg.getEndAirp()+"-"+fg.getFltNum());
    }
    v.setType(i);
    Date Dnnow = new Date();
    v.setTmstamp(Dnnow.getTime());
    session.save(v);
    tx.commit();
    i++;
    //break;
}


Thanks for your help


Top
 Profile  
 
 Post subject: Re: For each and random insert in data base.
PostPosted: Tue Feb 01, 2011 9:01 pm 
Newbie

Joined: Tue Feb 01, 2011 8:17 pm
Posts: 7
I found sorry ....
Hibernate work perfectly , it's because i have some common segment between some fly. So i have to use a relation many-to-many and not one-to-many.


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.