-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Unit testing hibernate code: inconsistent error
PostPosted: Wed Sep 07, 2005 10:31 pm 
Newbie

Joined: Tue Nov 16, 2004 10:18 pm
Posts: 8
Hibernate version: 3.0.5

Mapping documents: N.A.

Code between sessionFactory.openSession() and session.close(): N.A.

Full stack trace of any exception that occurs:
11:46:30,458 INFO DefaultLoadEventListener:85 - Error performing load command
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.tougher.intranet2.employee.grouping.Grouping#171]
at org.hibernate.ObjectNotFoundException.throwIfNull(ObjectNotFoundException.java:27)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:118)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:75)
at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:643)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:59)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
at com.tougher.intranet2.employee.grouping.Grouping$$EnhancerByCGLIB$$c5064040.toString(<generated>)
at java.lang.String.valueOf(String.java:2131)
at java.lang.StringBuffer.append(StringBuffer.java:370)
at com.tougher.intranet2.employee.unit.testing.UnitFacadeTransactionTest.testupdateUnitWithoutGroupingChangeUnitNameAndExistingGrouping(UnitFacadeTransactionTest.java:251)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
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:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)


Name and version of the database you are using:
MySQL 4.1.9

The generated SQL (show_sql=true):
Hibernate: select unit0_.unit_code as unit1_0_, unit0_.unit_name as unit2_1_0_, unit0_.group_code as group3_1_0_, unit0_.super_unit_code as super4_1_0_ from unit unit0_ where unit0_.unit_code=?
Hibernate: select grouping0_.group_code as group1_0_, grouping0_.group_name as group2_0_0_ from grouping grouping0_ where grouping0_.group_code=?


Debug level Hibernate log excerpt:
Hibernate: select unit0_.unit_code as unit1_0_, unit0_.unit_name as unit2_1_0_, unit0_.group_code as group3_1_0_, unit0_.super_unit_code as super4_1_0_ from unit unit0_ where unit0_.unit_code=?
Hibernate: select grouping0_.group_code as group1_0_, grouping0_.group_name as group2_0_0_ from grouping grouping0_ where grouping0_.group_code=?
11:46:30,458 INFO DefaultLoadEventListener:85 - Error performing load command


Hello,

I'm having a puzzling problem with Hibernate.
I'm using JUnit to test my business methods.
On setup, I clear the session so every test case has the same initial state.

I just have 2 classes now, Grouping and Unit,
where a Unit belongs to a Grouping.
When I run all of the test cases in the Unit test case,
there is that one error with the method
testupdateUnitWithoutGroupingChangeUnitNameAndExistingGrouping
(com.tougher.intranet2.employee.unit.testing.UnitFacadeTransactionTest)

The puzzling thing is that when I run it alone, it succeeds.
When I move it one method up or one method down
and run the whole test, it succeeds.
But when it is in its current position, it fails.
The problem is consistent, meaning, even when I run the test as a whole again,
the same failure happens.

The line that's throwing an Exception is
just a simple retrieval of a Unit object, with an associated Grouping.
The problem as I see it is that it is retrieving a non-existent Grouping.
When I debug it and look at the database before retrieval,
the data in the database exists.
For this particular test case, the group_code should be -4,
as in the database, not 171, as it is in the log.

I'm very sorry but I really have no idea what or where the problem is.
I might as well give the whole project,
and see if anyone can figure out what's wrong.
The file would be available for one week only.
It contains all files including sql file for filling tables.

Thanks in advance.

http://s34.yousendit.com/d.aspx?id=3CJASDPSY5I7P0DKPMWO2KH3V3


Top
 Profile  
 
 Post subject: Re: Unit testing hibernate code: inconsistent error
PostPosted: Wed Sep 07, 2005 11:00 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Why would you think both your mapping documents and the code between the session open/close are N/A ?

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: Re: Unit testing hibernate code: inconsistent error
PostPosted: Wed Sep 07, 2005 11:19 pm 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
pksiv wrote:
Why would you think both your mapping documents and the code between the session open/close are N/A ?


Why would you think if he says he might as well post the whole project, and puts a link to it, that the mapping documents and code are not in there? :)

What happens if you try to put a HibernateUtils.closeSession() in the tearDown(), so you get a new Session in each test? Or does this not mesh with how you set up your tests (didnt look in detail).

Chris


Top
 Profile  
 
 Post subject: Re: Unit testing hibernate code: inconsistent error
PostPosted: Thu Sep 08, 2005 12:00 am 
Newbie

Joined: Tue Nov 16, 2004 10:18 pm
Posts: 8
pksiv wrote:
Why would you think both your mapping documents and the code between the session open/close are N/A ?


Pksiv: The mapping files and the code between the session open/close are in the zip file.
I put N.A. because I thought the mapping is fine because the test succeeds on its own, although of course I may be wrong.

Chris
Quote:
Why would you think if he says he might as well post the whole project, and puts a link to it, that the mapping documents and code are not in there? :)

What happens if you try to put a HibernateUtils.closeSession() in the tearDown(), so you get a new Session in each test? Or does this not mesh with how you set up your tests (didnt look in detail).

Chris


Chris: Tried that, but the test still fails...


Top
 Profile  
 
 Post subject: Re: Unit testing hibernate code: inconsistent error
PostPosted: Thu Sep 08, 2005 8:06 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
oliverchua wrote:
pksiv wrote:
Why would you think both your mapping documents and the code between the session open/close are N/A ?


Pksiv: The mapping files and the code between the session open/close are in the zip file.
I put N.A. because I thought the mapping is fine because the test succeeds on its own, although of course I may be wrong.


Sorry. I missed that. Maybe instead of NA you should've put the link or at least mentioned that it was there.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.