Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

How to Optimize Hibernate buildSessionFactory();

 
Ranch Hand
Posts: 41
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to Optimize Hibernate buildSessionFactory();"


Im trying to optimize my hibernate initialization.
'cfg.buildSessionFactory();' consumes a lot of CPU. And on low-end systems is taking more than 20 seconds.
Is there anyway I can cache it and just load manually?

Im stuck. I cant find a way to optimize this. Whats the proper way to
make 'cfg.buildSessionFactory();' faster?





**Additional Information:**

----
    compile group: 'org.hibernate', name: 'hibernate-c3p0', version: '5.4.27.Final'
----

Mapping xml file: (I redacted private information as REDACTED)




**References**

https://forum.hibernate.org/viewtopic.php?p=2242766

https://developer.jboss.org/thread/197521

https://github.com/spring-projects/spring-framework/issues/18305

https://docs.jboss.org/hibernate/orm/5.2/topical/html_single/bytecode/BytecodeEnhancement.html
 
Saloon Keeper
Posts: 23441
159
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apparently buildSessionFactory() was deprecated as far back as 2011. That's 10 years of software erosion there.

It's also, I assume, part of legacy Hibernate, not Hibernate JPA, and I've been recommending that people migrate to JPA for many years now.

It's not true that you can write software and it "never wears out". The software may remain unchanged, but the world that contains it does not, and eventually, not only is it more and more likely to fail in time and  there will be fewer and fewer people who can help.

And, alas, I'm not one of them.
 
Castiel Snow
Ranch Hand
Posts: 41
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Apparently buildSessionFactory() was deprecated as far back as 2011. That's 10 years of software erosion there.

It's also, I assume, part of legacy Hibernate, not Hibernate JPA, and I've been recommending that people migrate to JPA for many years now.

It's not true that you can write software and it "never wears out". The software may remain unchanged, but the world that contains it does not, and eventually, not only is it more and more likely to fail in time and  there will be fewer and fewer people who can help.

And, alas, I'm not one of them.



Wow
I didnt know that!

How do I migrate to JPA? How do I start?
Im googling.. seems I can convert my actual code.

Something like this should work?



https://stackoverflow.com/questions/8640619/hibernate-serviceregistrybuilder


Or even this? https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/3-ways-to-build-a-Hibernate-SessionFactory-in-Java-by-example
 
Tim Holloway
Saloon Keeper
Posts: 23441
159
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JPA and Hibernate (legacy) are a lot alike, and that's not surprising, since the Hibernate people were major contributors in the design of JPA. But there are some key differences.

First, JPA doesn't have "sessions". That, in fact, is what usually keys me into when a Hibernate question here on the Ranch means legacy Hibernate and not Hibernate JPA.

JPA entity class definitions are marked with the "@Entity" tag. I think that so did later versions of legacy Hibernate, but I'm not sure.

You interact with the persistent store (database) using an EntityManager, which you obtain from an EntityManagerFactory. JEE full-stack containers provide their own Entity Manager services, incidentally, as JPA is a subset of EJB version 3, and in fact, the EJB service provider in the Wildfly JEE server is an embedded copy of Hibernate. Tomcat and jetty are not full-stack, so they have to provide their own entity management services, which I do with the assistance of the Spring Framework (Spring JPA). It works quite well. You can even use JPA in ordinary Java Applications (I've done so), which was something that EJB versions 1 and 2 didn't support.

If memory serves, legacy Hibernate had a Hibernate Query Language. The JPA equivalent is JPQL and it's SQL-like. You can also create native SQL queries in JPA, but doing so lessens its effectiveness, so I recommend only doing so for the really weird stuff that can't be done in JPQL.

There are many good books, articles, blogs, and so forth that cover JPA. I have a rather old but excellent text from aPress, myself. And of course, JPA is well-supported in a lot of online forums, including this one.
 
Where does a nanny get ground to air missles? Protect this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic