-->
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.  [ 7 posts ] 
Author Message
 Post subject: Does Hibernate throw and error if the result set is above a
PostPosted: Thu Dec 21, 2006 12:28 pm 
Newbie

Joined: Fri Dec 15, 2006 5:49 pm
Posts: 16
Does Hibernate throw and error if the result set is above a specific #
of records?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 1:05 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
By default, no. It will try and load everything retrieved even until an OutOfMemoryError if there's a lot of results.

But maybe have a look at the session.setMaxResults(int) method.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject: org.hibernate.exception.GenericJDBCException: could not load
PostPosted: Thu Dec 21, 2006 4:43 pm 
Newbie

Joined: Fri Dec 15, 2006 5:49 pm
Posts: 16
before I was running a single update as below and it worked fine:
Code:
    session.beginTransaction();
    /*
     int taskId = Integer.parseInt(request.getParameter("taskId"));
     String action_taken = request.getParameter("action_taken");

       WorkListErrors worklistErrors
       = (WorkListErrors) session.load(WorkListErrors.class, new Integer(taskId));
       
       worklistErrors.setAction_taken(action_taken);
       session.update(worklistErrors);
       session.save(worklistErrors);
      
       session.getTransaction().commit();   


but when I try an an update on multiple records it does work when I have a check box checked :

Code:
    session.beginTransaction();
    /*
     int taskId = Integer.parseInt(request.getParameter("taskId"));
     String action_taken = request.getParameter("action_taken");

       WorkListErrors worklistErrors
       = (WorkListErrors) session.load(WorkListErrors.class, new Integer(taskId));
       
       worklistErrors.setAction_taken(action_taken);
       session.update(worklistErrors);
       session.save(worklistErrors);
      
       session.getTransaction().commit();   


    session.beginTransaction();
     String[] tickedTaskId = request.getParameterValues("tickedTaskId");
    String[] taskId = request.getParameterValues("taskId");
     String[] action_taken = request.getParameterValues("action_taken");
     
     for(int i=0; i<tickedTaskId.length; i++) {

       for(int j = 0; j < taskId.length; j++) {
           
           if(tickedTaskId[i].equals(taskId[j])) {

               WorkListErrors worklistErrors
               = (WorkListErrors) session.load(WorkListErrors.class, tickedTaskId[i]);
               
               worklistErrors.setAction_taken(action_taken[j]);
               session.update(worklistErrors);
               session.save(worklistErrors);
              
               session.getTransaction().commit();   
           }
           
        }
     }     
   
   
     /*Close session */
      session.close();


Top
 Profile  
 
 Post subject: Re: org.hibernate.exception.GenericJDBCException: could not
PostPosted: Thu Dec 21, 2006 6:42 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
SuperMan2000 wrote:
but when I try an an update on multiple records it does work when I have a check box checked :

I absolutely don't see what you're speaking about : "check box checked" :-/.

This code is quite bizarre:
Code:
session.update(worklistErrors);
session.save(worklistErrors);

updating, THEN saving? Are you sure you shouldn't just do one of these operations?

Moreover, you're doing a batch-processing. You should regularly flush() and clear() the cache as explained. I guess you should have a look in the reference documentation : http://www.hibernate.org/hib_docs/v3/re ... tch-update

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 22, 2006 1:24 pm 
Newbie

Joined: Fri Dec 15, 2006 5:49 pm
Posts: 16
I though you require a save after and update...


so is the below correct
Code:
session.update(taskItem);
session.getTransaction().commit();   
session.flush();
session.clear();
session.close();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 22, 2006 1:36 pm 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
You are doing some things incorrectly (several commits, for example).

Just read this:

http://www.hibernate.org/hib_docs/v3/re ... tch-update

and do the same.

_________________
andresgr (--don't forget to rate)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 22, 2006 5:49 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
SuperMan2000 wrote:
I though you require a save after and update...

No, you don't.

Quote:
so is the below correct
Code:
session.update(taskItem);
session.getTransaction().commit();   
session.flush();
session.clear();
session.close();


Yes, completely.

Even more to say: depending on your mapping, you should rarely need to ever call update(). In fact, calling save just says to Hibernate that the given instance must be saved in the db in the next flush(). At flush() time, Hibernate gets your id and see if it's null, for example (see the unsaved-value attribute semantics to understand this) and call a sequence to initialize it as a new INSERT. If it detects the id of your bean is not null, it then considers that it's an UPDATE that has to be called.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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