Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HibernateTemplate.load does not throw ObjectRetrievalFailureException [SPR-1164] #5866

Closed
spring-projects-issues opened this issue Jul 21, 2005 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply

Comments

@spring-projects-issues
Copy link
Collaborator

Eduardo Rocha opened SPR-1164 and commented

I have a test similar with HibernateTemplateTests, but not using mocks for Hibernate classes, but concrete classes. I have this test:

1 try {
2 Piloto piloto = dao.findById(1);
3 fail("piloto obtido=[" + piloto.toString() + "]");
4 } catch (ObjectRetrievalFailureException e) {
5 assertEquals(1, e.getIdentifier());
6 assertEquals(Piloto.class, e.getPersistentClass());
7 }

for the code:

public Piloto findById(int id) {
return (Piloto) getHibernateTemplate().load(Piloto.class, id);
}

The database is empty.

The test fails AFTER findByid (#2), because the dao seems to use lazy loading, and an exception is throw when a call is made to "piloto.toString()" (#3):

org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [dominio.Piloto#1]
at org.hibernate.ObjectNotFoundException.throwIfNull(ObjectNotFoundException.java:27)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:121)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:78)
at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:649)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:85)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:131)
at br.com.erocha.formula.dominio.Piloto$$EnhancerByCGLIB$$4514e186.toString(<generated>)
at br.com.erocha.formula.infraestrutura.dao.hibernate.HibernatePilotoDaoImplTest.testFindByIdPilotoInexistente(HibernatePilotoDaoImplTest.java:113)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


Affects: 1.2.1

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

That's not a problem with Spring's Hibernate support but rather with Hibernate itself. Spring simply delegates all those operations to the Hibernate Session.

Try switching to default-lazy="false" at the <hibernate-mapping> level in your mapping file. Hibernate3 has everything lazy by default.

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug status: declined A suggestion or change that we don't feel we should currently apply in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 10, 2019
@spring-projects-issues spring-projects-issues removed the type: bug A general bug label Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

2 participants