net.sf.hibernate.AssertionFailure: null id in entry (don't flush the Session after an exception occurs)
at net.sf.hibernate.impl.SessionImpl.checkId(SessionImpl.java:2661)
at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2485)
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2478)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2280)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2259)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at persistencia.ConvencaoDao.criaOuActualiza(ConvencaoDao.java:56)
at persistencia.TesteMock.testCria(TesteMock.java:25)
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:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
java amateur
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
While you are mocking out the Connection, you are not mocking out the hibernate session. So Hibernate tries to get a session and fails because it is a unit test and the db is not available.
Mocks do not imply TDD. Mocks only imply unit tests.
Out of curiousity, why are you passing an object to the method, instead of a Connection directly?
java amateur
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
If you want to test your DAO, you don't need to mock itself, but the objects it needs to collaborate with. In your example that would be the hibernate session (wich is a little bit hard to mock, unfortunately).
Does that help?
As an aside, you might want to look at EasyMock or JMock, which are more advanced dynamic mocking libraries.
java amateur
Originally posted by miguel lisboa:
so i'm saving my Convencao obj
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
java amateur
Originally posted by miguel lisboa:
i followed jMock's tutorial and when i wanted to run it ... dont know how...
tried adding a main but didnt know where to go from there
can someone tell how to do it? (i browsed docs and googled too, but didnt help)
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
java amateur
java amateur
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |