Why doesn't Spring throw a DataAccessException if Hibernate throws an ObjectNotFoundException?

Why isn't the Spring 3.0.4 HibernateTemplate method load() throw a DataAccessException or, more specifically, an ObjectRetrievalFailureException , in case Hibernate 3.3.2GA throws ObjectNotFoundException ?

 2010-12-15 13:16:03,939 133247782 [[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'] INFO org.hibernate.event.def.DefaultLoadEventListener - Error performing load command org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.db.spgit.abstrack.model.ConsUsCustomMark#78445AAD8] at org.hibernate.impl.SessionFactoryImpl$1.handleEntityNotFound(SessionFactoryImpl.java:375) ~[hibernate-3.2.1.ga.jar:3.2.1.ga] at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:145) ~[hibernate-3.2.1.ga.jar:3.2.1.ga] at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:179) ~[hibernate-3.2.1.ga.jar:3.2.1.ga] at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:103) ~[hibernate-3.2.1.ga.jar:3.2.1.ga] at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878) [hibernate-3.2.1.ga.jar:3.2.1.ga] at org.hibernate.impl.SessionImpl.load(SessionImpl.java:795) [hibernate-3.2.1.ga.jar:3.2.1.ga] at org.hibernate.impl.SessionImpl.load(SessionImpl.java:788) [hibernate-3.2.1.ga.jar:3.2.1.ga] at org.springframework.orm.hibernate3.HibernateTemplate$3.doInHibernate(HibernateTemplate.java:558) [spring-orm-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406) [spring-orm-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) [spring-orm-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.orm.hibernate3.HibernateTemplate.load(HibernateTemplate.java:551) [spring-orm-3.0.4.RELEASE.jar:3.0.4.RELEASE] at org.springframework.orm.hibernate3.HibernateTemplate.load(HibernateTemplate.java:545) [spring-orm-3.0.4.RELEASE.jar:3.0.4.RELEASE] 
+4
source share
2 answers

An exception is logged, not necessarily thrown. What you see is a log to the information level of the exception stack trace, performed by hibernation. If you look at the source code of DefaultLoadEventListener (line 134 in my version of the source), you will notice that it throws an exception and then restarts.

All we see here is the exception stack trace log - there is no evidence that spring is not throwing an exception.

+4
source

The org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException() method checks to see if net.sf.hibernate.ObjectNotFoundException is an exception. This means that it should throw an UncategorizedDataAccessException .

I do not know if this is constructive or superscript (i.e. error in spring).

0
source

Source: https://habr.com/ru/post/1332267/


All Articles