Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #40010

Re: Is there a simpler way to map Hibernate?

Newsgroups comp.lang.java.programmer
Date 2023-09-05 12:34 -0700
References (3 earlier) <ucslb3$3p6nj$1@dont-email.me> <f0746a5b-9125-4055-b2a4-de230c621f6cn@googlegroups.com> <ucsnkr$3pftv$1@dont-email.me> <69105518-21d7-468c-9774-e9ffb497677fn@googlegroups.com> <ucspf7$3ppii$1@dont-email.me>
Message-ID <74cf0893-49c0-46dc-8381-92244f60bde1n@googlegroups.com> (permalink)
Subject Re: Is there a simpler way to map Hibernate?
From "e.d.pro...@gmail.com" <e.d.programmer@gmail.com>

Show all headers | View raw


> Yes. Basically: 
> 
> EntityManagerFactory emf = Persistence.createEntityManagerFactory(confnam); 
> EntityManager em = emf.createEntityManager(); 
> 
> instead of: 
> 
> SessionFactory sf = new Configuration().configure(new 
> File(conffile)).buildSessionFactory(); 
> Session s = sf.openSession(); 
...
> 
> Arne

This is confusing. I've been implementing the openSession using try-with-resources.
org.hibernate.Session extends javax.persistence.EntityManager (I'm using Hibernate 5x since 6x requires newer Java, stuck using Java 8 for now) as well as Autocloseable.
EntityManager is not autocloseable, though if I'm reading this right, the first thread I found on stackoverflow suggests closing it after every use unless you're working with very small data.
If I'm creating the EntityManager directly instead of the Session, should I create my own wrapper to make it auto-closeable? Is there a good use case for not closing it? It causes memory leaks if you don't close it when you're done with it unless you're re-using the same one instead of creating a new one each time? I assume they can still be chained, like I create one in a DAO to access one DTO and while it's open I call a method of a different DAO to access a different DTO and it creates it's own EntityManager?

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Is there a simpler way to map Hibernate? "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-08-31 04:49 -0700
  Re: Is there a simpler way to map Hibernate? Arne Vajhøj <arne@vajhoej.dk> - 2023-08-31 18:46 -0400
    Re: Is there a simpler way to map Hibernate? "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-09-01 04:08 -0700
      Re: Is there a simpler way to map Hibernate? Arne Vajhøj <arne@vajhoej.dk> - 2023-09-01 08:27 -0400
        Re: Is there a simpler way to map Hibernate? "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-09-01 05:49 -0700
          Re: Is there a simpler way to map Hibernate? Arne Vajhøj <arne@vajhoej.dk> - 2023-09-01 09:06 -0400
            Re: Is there a simpler way to map Hibernate? "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-09-01 06:25 -0700
              Re: Is there a simpler way to map Hibernate? Arne Vajhøj <arne@vajhoej.dk> - 2023-09-01 09:37 -0400
                Re: Is there a simpler way to map Hibernate? "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-09-01 12:48 -0700
                Re: Is there a simpler way to map Hibernate? "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-09-05 12:34 -0700
                Re: Is there a simpler way to map Hibernate? Arne Vajhøj <arne@vajhoej.dk> - 2023-09-10 20:48 -0400
                Re: Is there a simpler way to map Hibernate? "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-09-11 04:19 -0700
                Re: Is there a simpler way to map Hibernate? "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-09-11 05:23 -0700

csiph-web