Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #40013
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2023-09-11 05:23 -0700 |
| References | (5 earlier) <ucsnkr$3pftv$1@dont-email.me> <69105518-21d7-468c-9774-e9ffb497677fn@googlegroups.com> <ucspf7$3ppii$1@dont-email.me> <74cf0893-49c0-46dc-8381-92244f60bde1n@googlegroups.com> <udlo4l$otip$1@dont-email.me> |
| Message-ID | <467de546-1da2-4943-83f8-4dd760f7c136n@googlegroups.com> (permalink) |
| Subject | Re: Is there a simpler way to map Hibernate? |
| From | "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> |
> If Session extends EntityManager you should be able to
> use the JPA methods on Session and just use Session auto closeable
> feature.
>
> Arne
So I'm trying this.
I deleted hibernate.cfg.xml. I created src/main/resources/META-INF/hibernate.xml.
My hibernate.xml has a persistence-unit with the <exclude-unlisted-classes>false and 5 properties defining the JDBC connection, no class specific mappings.
I read on one S/O that the unwrap(Session.class) should return a Session, it didn't.
We have a final class with a private static factory. I changed that factory from the hibernate factory to EntityManagerFactory.
Now it has a static method I changed to:
public static Session getHibernateSession() {
if (factory == null) {
factory = Persistence.createEntityManagerFactory("mypersistenceunit.jpa");
}
Object delegate = factory.createEntityManager().getDelegate();
if (delegate instanceof Session) {
return (Session) delegate;
}
return factory.unwrap(Session.class);
}
We call this method from try-with-resources. This is working. The next apparent question is do we want to be referencing org.hibernate.Session? One site says use EntityManager to keep it generic because there are framework alternatives to Hibernate ("like EclipseLink or TopLink"?). It seems Hibernate is supposed to be "under the hood" so we have few if any references to it outside of the pom and persistence.xml.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll 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