-->
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.  [ 6 posts ] 
Author Message
 Post subject: Update Ant file and jars for latest Hibernate version
PostPosted: Tue Nov 28, 2017 4:23 am 
Newbie

Joined: Tue Nov 21, 2017 5:48 pm
Posts: 5
hi there..
i'm writing an desktop application and i'm using hibernate for persistence, and i'm using free form project and ant files.

i want update hibernate at latest version,
actually, i'm using 4.1 version.

in ant file i has :
Code:
hibernate.ver             = 4.1
hibernate-tools.ver       = 4.1
hibernate-annotations.ver = 4.1


// this is swing ant file
<path id="hibernate.classpath">
        <fileset refid="hibernate.jars" />       
        <fileset refid="hibernate-annotations.jars" />
</path>




// this is my framework-hibernate-template-build.xml

Code:
    <echo message="Versione di Hibernate: ${hibernate.ver}" />

    <fileset id="hibernate.jars" dir="${lib.dir}/hibernate-${hibernate.ver}">
        <include name="antlr-*.jar" />
        <include name="commons-collections-*.jar" />
        <include name="dom4j-*.jar" />
        <include name="hibernate*.jar" />
        <include name="hibernate-jpa*.jar" />
        <include name="javassist*.jar" />
        <include name="jboss-*.jar" />
        <!-- <include name="c3p0-*.jar" />
        <include name="mchange-*.jar" /> -->
    </fileset>
   
    <echo message="Versione di Hibernate-annotations: ${hibernate-annotations.ver}" />

    <fileset id="hibernate-annotations.jars" dir="${lib.dir}/hibernate-annotations-${hibernate-annotations.ver}">
        <include name="hibernate-commons-annotations*.jar" />
    </fileset>
     
    <echo message="Versione di Hibernate-tools: ${hibernate-tools.ver}" />

    <fileset id="hibernate-tools.jars" dir="${lib.dir}/hibernate-tools-${hibernate-tools.ver}">
        <include name="hibernate-tools*.jar" />
        <include name="freemarker.jar" />
        <include name="commons-logging-*.jar" />
    </fileset>



my problem is that if I download the new hibernate version I can not find the same folders and the jars files, can you tell me where to find them?

I want to upgrade to the latest version because I get this error
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
another post I read that it is advisable to first update.

Code:
SessionFactory sf = DAOUtilHibernate.getSessionFactory();
        IDAOSala dao = new DAOSala();
        try {
            sf.getCurrentSession().beginTransaction();
            Session session = (Session) sf.getCurrentSession();
            listaSale = dao.findAll();
            sf.getCurrentSession().getTransaction().commit();
            this.controllo.getModello().setListaSale(listaSale);
            return true;
           
        } catch (DAOException ex) {
            JOptionPane.showMessageDialog(this.controllo.getVista(), "Errore nel caricamento delle sale", "Inane error", JOptionPane.ERROR_MESSAGE);
            if (sf.getCurrentSession().getTransaction().isActive()) {
                logger.error("Trying to rollback database transaction after exception");
                sf.getCurrentSession().getTransaction().rollback();
            }
            logger.error("errore nel caricamento sala e tavoli " + ex);
            return false;
        }
    }


"Sale" --> is room
sale has a list of table.
Hibernate use lazy loading.
when my view call the table list, hibernate session is closed.
if i comment sf.getCurrentSession().getTransaction().commit();
the app works, but i don't know if is it correct or not
( one user, one session ? open with app and close when i close app?? it is a solution ? what does commit() method? )

thank you very much for your help!


Top
 Profile  
 
 Post subject: Re: Update ant file and jars at latest version
PostPosted: Tue Nov 28, 2017 5:20 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
Quote:
i want update hibernate at latest version,
actually, i'm using 4.1 version.


Hibernate 4.1 is a 6 year-old version. If you want to use the latest Hibernate, then use 5.2.12.

Quote:
In ant file i has :


Hibernate, like all major frameworks out there, does not support Ant anymore. We have Maven and Gradle plugins for Hibernate tools.

Quote:
my problem is that if I download the new hibernate version I can not find the same folders and the jars files, can you tell me where to find them?


No need to do that. Use Maven or Gradle and all your dependencies will be resolved automatically.

Quote:
I want to upgrade to the latest version because I get this error
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
another post I read that it is advisable to first update.


You don't need to upgrade because you get the LazyInitializationException. You will still get the LazyInitializationException even with 5.2 if you access a non-initialized proxy after the Hibernate Session is closed.

For more details about handling the LazyInitializationException, check out this article.


Top
 Profile  
 
 Post subject: Re: Update Ant file and jars for latest Hibernate version
PostPosted: Tue Nov 28, 2017 5:46 am 
Newbie

Joined: Tue Nov 21, 2017 5:48 pm
Posts: 5
thank you heartily for your precious suggestion.

now my question is this, would you recommend updating any project to maven or gradle, or continue with version 4.1?

thank you for everything, unfortunately I do the restaurateur, not the developer :( though having studied computer science at the university.
(the developers of my software though understand less than me and after months of promises of an upgrade never succeeded, I decided to write it myself)


thanks a lot
"Grazie !! "


Top
 Profile  
 
 Post subject: Re: Update Ant file and jars for latest Hibernate version
PostPosted: Tue Nov 28, 2017 5:54 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
Quote:
now my question is this, would you recommend updating any project to maven or gradle, or continue with version 4.1?


It depends on what is your goal for this migration.

If you are satisfied with 4.1 and do little development on this project, and mostly maintenance, then migrating might be justifiable.

However, if you want to do lots of development and benefit from the latest Hibernate improvements, then you should upgrade.


Top
 Profile  
 
 Post subject: Re: Update Ant file and jars for latest Hibernate version
PostPosted: Wed Nov 29, 2017 7:01 pm 
Newbie

Joined: Tue Nov 21, 2017 5:48 pm
Posts: 5
sorry if still disturbed, but just can not understand.
if I wanted to implement a lazy load of a much more complex structure as I do?

[img]
https://drive.google.com/file/d/1Tg8H3E ... eDru4/view
[/img]

I expected a simpler loading mechanism lazy.
  - Charge the rooms (restaurant rooms) open and close the session
- When I try to access the tables list (the restaurant tables) the system reopens the session, accesses the Tables table, and closes the session.
Code:
List<Sala> listaSale = new ArrayList();
        //List<Tavolo> listaTavoli = new ArrayList();
        SessionFactory sf = DAOUtilHibernate.getSessionFactory();
        IDAOSala dao = new DAOSala();
        try {
            sf.getCurrentSession().beginTransaction();
            Session session = (Session) sf.getCurrentSession();
            listaSale = dao.findAll();
            sf.getCurrentSession().getTransaction().commit();
            this.controllo.getModello().setListaSale(listaSale);
            return true;
           
        } catch (DAOException ex) {
            JOptionPane.showMessageDialog(this.controllo.getVista(), "Errore nel caricamento delle sale", "Inane error", JOptionPane.ERROR_MESSAGE);
            if (sf.getCurrentSession().getTransaction().isActive()) {
                logger.error("Trying to rollback database transaction after exception");
                sf.getCurrentSession().getTransaction().rollback();
            }
            logger.error("errore nel caricamento sala e tavoli " + ex);
            return false;
        }



For example, I would think of a method like the one shown, but only change the daoSala.findAll () method from time to time,
call the method by passing the same method as the parameter.

I can not understand the policy with which to implement lazy upload for my app :(

Forgive me for my uml diagram, for my errors and inaccuracies, but i'm about 10 years i do not write java code :(

Thanks for your patience
Marco


Top
 Profile  
 
 Post subject: Re: Update Ant file and jars for latest Hibernate version
PostPosted: Thu Nov 30, 2017 4:22 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
Quote:
I expected a simpler loading mechanism lazy.


The lazy loading mechanism is very simple.

Quote:
When I try to access the tables list (the restaurant tables) the system reopens the session, accesses the Tables table, and closes the session.


That's only the case if you enabled the hibernate.enable_lazy_load_no_trans configuration which is an Anti-Pattern.

Quote:
For example, I would think of a method like the one shown, but only change the daoSala.findAll () method from time to time,
call the method by passing the same method as the parameter.


Sounds like you can benefit from using EntityGraphs.

Quote:
Forgive me for my uml diagram, for my errors and inaccuracies, but i'm about 10 years i do not write java code :(


Using Hibernate without reading the User Guide is not advisable. Check out these tutorials as well.


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