hibernate-session

Listener on transaction start

一世执手 提交于 2020-02-01 05:19:53
问题 I am looking for a clean solution to have a listener for transaction start. That means I would like the listener to be a bean (component) in the spring context that would receive an event on transaction start from TransactionPlatformManager or Hibernate Session or something similar, at the point where a new transaction is started. Something along: @Component class TransactionListener implements ?? { @Autowired private Something x; public void onTransactionBegin(...) { x.doSomething() } } To

org.hibernate.service.UnknownServiceException: Unknown service requested

笑着哭i 提交于 2020-01-02 03:41:11
问题 I am writing a unit test to for my AbstractHibernateRepository save method. I'm using spring test runner but I get the following exception when it runs: org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider] at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:201) My Test: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("file:src/main/webapp/WEB

Spring Transactions and hibernate.current_session_context_class

▼魔方 西西 提交于 2019-12-27 14:42:31
问题 I have a Spring 3.2 application that uses Hibernate 4 and Spring Transactions. All the methods were working great and I could access correctly the database to save or retrieve entities. Then, I introduced some multithreading, and since each thread was accessing to db I was getting the following error from Hibernate: org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions I read from the web that I've to add <prop key="hibernate.current_session

java.lang.ClassNotFoundException: javax.persistence.NamedStoredProcedureQuery - Hibernate Error

空扰寡人 提交于 2019-12-22 11:34:25
问题 Above exception has been throwing While creating a hibernate session factory. In application lib folder have hibernate-jpa-2.1-api and javax.persistence.2.1.0. I can able to see the NamedStoredProcedureQuery class in both jar. But I am getting runtime error for classnotfoundexception. Any suggestion? 回答1: NamedStoredProcedureQuery class is available in hibernate-jpa-2.1-api jar. But this jar refers some other jar in run time. So I didn't get error in compile time and getting exception during

Hibernate: Difference between session.get and session.load

冷暖自知 提交于 2019-12-17 01:35:30
问题 From the API, I could see it has something to do with proxy. But I couldn't find a lot of information on proxy and do not understand the difference between calling session.get and session.load . Could someone please explain or direct me to a reference page? Thank you!! 回答1: From the Hibernate forum: This from the book Hibernate in Action. Good one read this.. Retrieving objects by identifier The following Hibernate code snippet retrieves a User object from the database: User user = (User)

Grails withNewSession does not flush

旧街凉风 提交于 2019-12-11 03:49:49
问题 In a grails Domain a have implemented the beforeDelete as follow class Shop { def beforeDelete() { Shop.withNewSession { Client.findAllByShop(this)*.shop = null } } } But the client shop null value is not persisted to the DB. If I add a manual session flush class Shop { def beforeDelete() { Shop.withNewSession { s2-> Client.findAllByShop(this)*.shop = null s2.flush() s2.clear() } } } It works, the client shop value are nulled in the db. Is this a Grails bug or I have misunderstand the

Hibernate, session, lazyloading

醉酒当歌 提交于 2019-12-10 08:23:00
问题 I am developing a Java web application using Hibernate and JSF/primefaces. am sometimes getting errors like 1) an object with same identifier is already associated with session. 2) failed to load lazy initialization * ,no session exist or session is already closed. I know this is due to improper coding in my app. this is the way am doing aap: When a user requests for a page(Let it be a list of Employees). the user will get the employee list page(empployeeList.xhtml) EmployeeListMBean is the

java.lang.ClassNotFoundException: javax.persistence.NamedStoredProcedureQuery - Hibernate Error

元气小坏坏 提交于 2019-12-05 22:33:24
Above exception has been throwing While creating a hibernate session factory. In application lib folder have hibernate-jpa-2.1-api and javax.persistence.2.1.0. I can able to see the NamedStoredProcedureQuery class in both jar. But I am getting runtime error for classnotfoundexception. Any suggestion? NamedStoredProcedureQuery class is available in hibernate-jpa-2.1-api jar. But this jar refers some other jar in run time. So I didn't get error in compile time and getting exception during runtime. I just added other hibernated libs through maven repository.Initially i used only hibernate-core.

Hibernate, session, lazyloading

爷,独闯天下 提交于 2019-12-05 19:15:24
I am developing a Java web application using Hibernate and JSF/primefaces. am sometimes getting errors like 1) an object with same identifier is already associated with session. 2) failed to load lazy initialization * ,no session exist or session is already closed. I know this is due to improper coding in my app. this is the way am doing aap: When a user requests for a page(Let it be a list of Employees). the user will get the employee list page(empployeeList.xhtml) EmployeeListMBean is the managed bean for this page. in the managed bean in the constructor, am calling a method

org.hibernate.service.UnknownServiceException: Unknown service requested

≡放荡痞女 提交于 2019-12-05 07:42:57
I am writing a unit test to for my AbstractHibernateRepository save method. I'm using spring test runner but I get the following exception when it runs: org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider] at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:201) My Test: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("file:src/main/webapp/WEB-INF/spring/spring-hibernate.xml") public class AbstractHibernateRepoTest extends AbstractHibernateRepo