5 Replies Latest reply on Jul 25, 2006 7:14 AM by Oleg Zhurakousky

    How to configure batch/fetch size

    Qba C Newbie

      Hi,

      Recently I wrote a simple application (EJB3.0), which reads all rows of one unrelated table.
      My problem is that I want to set batch (or fetch - i don't know which term is appropriate) size. As I look at the session trace in oracle 10g, i get, thath it is fetching the data in 10-row packs (73 rows, 8 fetches) . However, during the deployment, I get this message form JBoss:

      INFO [SettingsFactory] JDBC batch size: 15


      How can I change that size? It would be great if there is some way to change it for this specific app. I was trying to find out, if there's any way to do this by configuring the persistence.xml, but i couldn't find any docs about it.


        • 1. Re: How to configure batch/fetch size
          Oleg Zhurakousky Newbie

          Yes you should do it in persistance.xml
          Try this:

          
          <persistence>
           . . . . . . . .
           <properties>
           <property name="hibernate.jdbc.batch_size" value="25"/>
           . . . . . . .
           </properties>
           . . . . . . . .
          </persistence>
          
          


          Regards

          Oleg Zhurakousky

          • 2. Re: How to configure batch/fetch size
            Qba C Newbie

            Well, I tried this, but it didn't work.
            Here's my persistence.xml

            <?xml version="1.0" encoding="UTF-8"?>
            <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
             <persistence-unit name="DBTestOne-ejb" transaction-type="JTA">
             <provider>org.hibernate.ejb.HibernatePersistence</provider>
             <jta-data-source>OracleDS</jta-data-source>
             <class>DBTest.EJBTestEntity</class>
             <properties>
             <property name="hibernate.jdbc.batch_size" value="25"/>
             </properties>
             </persistence-unit>
            </persistence>
            


            The database logs show, that there are 73 rows in 8 fetches.

            Here's the code of the session bean thath queries the database:
            @Stateless
            public class EJBTestSessionBean implements DBTest.EJBTestSessionRemote {
            
             @PersistenceContext
             EntityManager em;
            
             public EJBTestSessionBean() {}
            
            public Collection<EJBTestEntity> getEJBTestEntity(){
             Query query;
             query = em.createQuery("from EJBTestEntity t"); /
             return query.getResultList();
             }
            }



            • 3. Re: How to configure batch/fetch size
              Oleg Zhurakousky Newbie

              Believe me, I hate to say it, but it does work for me here. . .
              Do you have any other EJB3 configuration deployed?

              Here is what I get:

              08:34:54,743 INFO [SettingsFactory] JDBC batch size: 19
              

              and here is my persistance.xml
              <?xml version="1.0" encoding="UTF-8"?>
              <persistence>
               <persistence-unit name="tempdb">
               <provider>org.hibernate.ejb.HibernatePersistence</provider>
               <jta-data-source>java:/MySqlDS</jta-data-source>
               <properties>
               <property name="hibernate.jdbc.batch_size" value="19"/>
               </properties>
               </persistence-unit>
              </persistence>


              • 4. Re: How to configure batch/fetch size
                Qba C Newbie

                Finally, I found a solution to this.

                The property to set in persistence.xml is "hibernate.jdbc.fetch_size".

                Thank You azhurakousky, You were very helpful to me :)

                • 5. Re: How to configure batch/fetch size
                  Oleg Zhurakousky Newbie

                  Ahh. . .
                  So it wasn't a "batch size", but a "fetch_size". Different property, but I am glad you found a way

                  Oleg