Hi,
I'm currently using Hibernate without Spring and what you want to
achieve can be done in several steps:
- prepare your org.hibernate.cfg.Configuration
- set Configuration's property:
config.setProperty("hibernate.current_session_context_class", "managed");
- get SessionFactory by caling org.hibernate.cfg.Configuration.build()
- store SessionFactory's instance somewhere and keep it for the duration
of your application
- when you request a session, bind it:
Session sess = sessionFactory.openSession();
ManagedSessionContext.bind(sess);
- at the end of request cycle, unbind SessionFactory. Implement your own
IRequestCycleListener and in IRequestCycleListener.onEndRequest call
unbind logic.
Here's what I use:
public void unbindSessionFactory(Object key, boolean closeSessionFactory)
{
SessionFactory sf = getHibernateSessionFactory(key);
if (hasBoundSession(sf))
{
Session sess = sf.getCurrentSession();
if (sess.isOpen())
{
try
{
if (sess.getTransaction().isActive())
{
sess.getTransaction().rollback();
}
}
finally
{
sess.close();
}
}
ManagedSessionContext.unbind(sf);
if (closeSessionFactory)
sf.close();
}
}
- when application exits, close session factory
Hope that helped.
Vit
On 22. 12. 22 8:23, James wrote:
Thanks for the guidance so far, that pointed me to find additional
resources on JPA
I believe I have this configured correctly, but I'm confused about how
to integrate JPA/Hibernate into a
pure wicket authenticated web application project since the resource
you directed me to previously
seems to be more heavily on the spring side of things.
Thank you for accommodating all my questions and misunderstandings so
far, I tend to use a reverse
engineer learning style so it's helped me immensely.
I've included screenshots of the project file list and the application
class in the hopes that it makes
understanding what I'm trying to convey easier
Best Regards
James Pollard
[email protected]
On 20/12/22 12:58 pm, Ernesto Reinaldo Barreiro wrote:
https://github.com/MarcGiffing/wicket-spring-boot/blob/master/wicket-spring-boot-starter-example/src/main/java/com/giffing/wicket/spring/boot/example/model/Customer.java
This defines a JPA entity.... and this JPA/Hibernate
https://github.com/MarcGiffing/wicket-spring-boot/blob/master/wicket-spring-boot-starter-example/src/main/resources/application.yml
Project uses Spring magic I guess and will start a Hibernate with H2.
Wicket is also started via SpringBoot.
On Tue, Dec 20, 2022 at 7:44 AM James <[email protected]>
wrote:
I've had a look through it but couldn't find any reference to hibernate
so far, its entirely
possible that I managed to miss it while I was searching though
Best Regards
James Pollard
[email protected]
On 19/12/22 5:06 pm, Ernesto Reinaldo Barreiro wrote:
Hi,
This project
https://github.com/MarcGiffing/wicket-spring-boot
contains a sample project that integrates with JPA/hibernate.
On Mon, Dec 19, 2022 at 9:12 AM James <[email protected]>
wrote:
Hi,
can anyone direct me to any resources on how to integrate
hibernate for
data persistence?
the closest I've managed to find is
https://www.infoworld.com/article/2077901/web-development-with-wicket--part-3--many-ways-to-persist.html?page=7
but there's still things that are confusing me on how to ingrate an
authenticated application with hibernate
--
Best Regards
James Pollard
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]