I use autoincrement, but I had already some sample data in the db. So you
were right, the rollback doesn't really work. I don't know exactly why. 
For the tests I'm now using the code below, like that you are sure to update
the right row and just the second one. 

public void testSaveResident() throws Exception {
                Long residentId = null;
                resident = new Resident();
                resident.setFirstName("Bernd");
                resident.setLastName("Putsche");
               
                dao.saveResident(resident);
                //resident = dao.getResident(resident.getId());
                residentId = resident.getId();
                resident = dao.getResident(residentId);
                System.out.println("CHECK ID:" + resident.getId());
               
                resident.setFirstName("Bernd");
                resident.setLastName("Putsche update");
               
                dao.saveResident(resident);
               
                if (log.isDebugEnabled()) {
                        log.debug("updated Resident: " + resident);
                }
               
                assertEquals(resident.getLastName(), "Putsche update");
        } 


Stefan


cosmonate cosmo wrote:
> 
> did you use autoincrement for your ids?
> 
> /**
>        * Getter for Id
>        * @return Id
>        * @hibernate.id column="id" generator-class="increment" unsaved- 
> value="null"
>        */
>       public Long getId() {
>           return id;
>       }
> 
> 
> On Jan 12, 2007, at 4:31 PM, Stefan Malär wrote:
> 
>>
>> For me worked:
>> public void testSavePerson() throws Exception {
>>         person = new Person();
>>         person.setFirstName("Stefan");
>>         person.setLastName("Malaer");
>>
>>         dao.savePerson(person);
>>      
>>         person = dao.getPerson(new Long(1));
>>         person.setFirstName("Stefan");
>>
>>         person.setLastName("Last Name Updated");
>>
>>         dao.savePerson(person);
>>
>>         if (log.isDebugEnabled()) {
>>             log.debug("updated Person: " + person);
>>         }
>>
>>         assertEquals(person.getLastName(), "Last Name Updated");
>>     }
>> Maybe something with the rollback went wrong in your test.
>>
>> Stefan
>>
>>
>> cosmonate cosmo wrote:
>>>
>>> it seems so! so i did create new resident but, but auto inkrement
>>> gives the new resident id=2 not 1! i checked this.. so there is some
>>> inconsistency  in the tutorial and the way it really works i think!?
>>>
>>> isn't resident/person createt in test1 with id=1 removed after the
>>> rollback of the test/transaction?
>>>
>>> this is the code i use now, and it works
>>>
>>> it's similar to the one in the tutorial except the testSave...()  
>>> method:
>>>
>>> package at.carenet.dao;
>>>
>>> import at.carenet.model.Resident;
>>> import org.springframework.dao.DataAccessException;
>>>
>>> public class ResidentDaoTest extends BaseDaoTestCase
>>> {
>>>     private Resident resident = null;
>>>     private ResidentDao dao = null;
>>>     
>>>     public void setResidentDao(ResidentDao dao) {
>>>             this.dao = dao;
>>>     }
>>>     
>>>     public void testGetResident() throws Exception {
>>>             resident = new Resident();
>>>             resident.setFirstName("Bernd");
>>>             resident.setLastName("Putsche");
>>>             
>>>             dao.saveResident(resident);
>>>             assertNotNull(resident.getId());
>>>             
>>>             resident = dao.getResident(resident.getId());
>>>             System.out.println("CHECK ID:" + resident.getId());
>>>             assertEquals(resident.getFirstName(), "Bernd");
>>>     }
>>>     
>>>     public void testSaveResident() throws Exception {
>>>             resident = new Resident();
>>>             resident.setFirstName("Bernd");
>>>             resident.setLastName("Putsche");
>>>             
>>>             dao.saveResident(resident);
>>>             //resident = dao.getResident(resident.getId());
>>>             resident = dao.getResident(new Long(2));
>>>             System.out.println("CHECK ID:" + resident.getId());
>>>             
>>>             resident.setFirstName("Bernd");
>>>             resident.setLastName("Putsche update");
>>>             
>>>             dao.saveResident(resident);
>>>             
>>>             if (log.isDebugEnabled()) {
>>>                     log.debug("updated Resident: " + resident);
>>>             }
>>>             
>>>             assertEquals(resident.getLastName(), "Putsche update");
>>>     }
>>>     
>>>     public void testAddAndRemoveResident() throws Exception {
>>>             resident = new Resident();
>>>             resident.setFirstName("Bill");
>>>             resident.setLastName("Joy");
>>>
>>>             dao.saveResident(resident);
>>>             System.out.println("CHECK ID:" + resident.getId());
>>>             assertEquals(resident.getFirstName(), "Bill");
>>>             assertNotNull(resident.getId());
>>>
>>>             if (log.isDebugEnabled()) {
>>>                     log.debug("removing person...");
>>>             }
>>>
>>>             dao.removeResident(resident.getId());
>>>
>>>             try {
>>>                 resident = dao.getResident(resident.getId());
>>>                 fail("Resident found in database");
>>>             } catch (DataAccessException dae) {
>>>                 log.debug("Expected exception: " + dae.getMessage());
>>>                 assertNotNull(dae);
>>>             }
>>>     }       
>>> }
>>>
>>> bernd
>>>
>>>
>>> On Jan 12, 2007, at 1:23 PM, Stefan Malär wrote:
>>>
>>>>
>>>> Hi Bernd
>>>>
>>>> Most likely the error occurs because you trying to do something like
>>>> resident = dao.getResident(new Long(1));
>>>> in your testSaveResident method. But there is no Resident in your  
>>>> dao
>>>> object.
>>>> Instead you have to create a Resident to be saved by writing
>>>> resident = new Resident();
>>>>
>>>> Hope that helps.
>>>>
>>>> Stefan
>>>>
>>>>
>>>> cosmonate cosmo wrote:
>>>>>
>>>>> well now i get another error :-(
>>>>>
>>>>> tests 1 and 3 run successful , but 2 ( testSaveResident in my case)
>>>>> fails when retrieving object with identifier 1
>>>>>
>>>>> the class is called Resident and getResident() works in test 1  
>>>>> and 3,
>>>>> but fails in test 2!
>>>>>
>>>>> OUTPUT:
>>>>> test-dao:
>>>>>       [echo] Testing dao...
>>>>>      [junit] [carenet] INFO [main]
>>>>> ResidentDaoTest.loadContextLocations(136) | Loading context for:
>>>>> classpath*:/**/dao/applicationContext-*.xml,classpath*:META-INF/
>>>>> applicationContext-*.xml
>>>>>      [junit] [carenet] INFO [main]
>>>>> ResidentDaoTest.startNewTransaction
>>>>> (309) | Began transaction (1): transaction manager
>>>>> [EMAIL PROTECTED] 
>>>>> 16
>>>>> 0];
>>>>>   default rollback = true
>>>>>      [junit] [carenet] INFO [main] ResidentDaoTest.endTransaction
>>>>> (275) | Rolled back transaction after test execution
>>>>>      [junit] [carenet] INFO [main]
>>>>> ResidentDaoTest.startNewTransaction
>>>>> (309) | Began transaction (1): transaction manager
>>>>> [EMAIL PROTECTED] 
>>>>> 16
>>>>> 0];
>>>>>   default rollback = true
>>>>>      [junit] [carenet] INFO [main] ResidentDaoTest.endTransaction
>>>>> (275) | Rolled back transaction after test execution
>>>>>      [junit] [carenet] INFO [main]
>>>>> ResidentDaoTest.startNewTransaction
>>>>> (309) | Began transaction (1): transaction manager
>>>>> [EMAIL PROTECTED] 
>>>>> 16
>>>>> 0];
>>>>>   default rollback = true
>>>>>      [junit] [carenet] DEBUG [main]
>>>>> ResidentDaoTest.testAddAndRemoveResident(55) | removing person...
>>>>>      [junit] [carenet] DEBUG [main]
>>>>> ResidentDaoTest.testAddAndRemoveResident(64) | Expected exception:
>>>>> Object of class [at.carenet.model.Resident] with identifier [2]:  
>>>>> not
>>>>> found
>>>>>      [junit] [carenet] INFO [main] ResidentDaoTest.endTransaction
>>>>> (275) | Rolled back transaction after test execution
>>>>>      [junit] Testsuite: at.carenet.dao.ResidentDaoTest
>>>>>      [junit] Tests run: 3, Failures: 0, Errors: 1, Time elapsed:
>>>>> 7.933 sec
>>>>>
>>>>>      [junit] ------------- Standard Output ---------------
>>>>>      [junit] [carenet] INFO [main]
>>>>> ResidentDaoTest.loadContextLocations(136) | Loading context for:
>>>>> classpath*:/**/dao/applicationContext-*.xml,classpath*:META-INF/
>>>>> applicationContext-*.xml
>>>>>      [junit] [carenet] INFO [main]
>>>>> ResidentDaoTest.startNewTransaction
>>>>> (309) | Began transaction (1): transaction manager
>>>>> [EMAIL PROTECTED] 
>>>>> 16
>>>>> 0];
>>>>>   default rollback = true
>>>>>      [junit] [carenet] INFO [main] ResidentDaoTest.endTransaction
>>>>> (275) | Rolled back transaction after test execution
>>>>>      [junit] [carenet] INFO [main]
>>>>> ResidentDaoTest.startNewTransaction
>>>>> (309) | Began transaction (1): transaction manager
>>>>> [EMAIL PROTECTED] 
>>>>> 16
>>>>> 0];
>>>>>   default rollback = true
>>>>>      [junit] [carenet] INFO [main] ResidentDaoTest.endTransaction
>>>>> (275) | Rolled back transaction after test execution
>>>>>      [junit] [carenet] INFO [main]
>>>>> ResidentDaoTest.startNewTransaction
>>>>> (309) | Began transaction (1): transaction manager
>>>>> [EMAIL PROTECTED] 
>>>>> 16
>>>>> 0];
>>>>>   default rollback = true
>>>>>      [junit] [carenet] DEBUG [main]
>>>>> ResidentDaoTest.testAddAndRemoveResident(55) | removing person...
>>>>>      [junit] [carenet] DEBUG [main]
>>>>> ResidentDaoTest.testAddAndRemoveResident(64) | Expected exception:
>>>>> Object of class [at.carenet.model.Resident] with identifier [2]:  
>>>>> not
>>>>> found
>>>>>      [junit] [carenet] INFO [main] ResidentDaoTest.endTransaction
>>>>> (275) | Rolled back transaction after test execution
>>>>>      [junit] ------------- ---------------- ---------------
>>>>>      [junit] Testcase: testSaveResident
>>>>> (at.carenet.dao.ResidentDaoTest): Caused an ERROR
>>>>>      [junit] Object of class [at.carenet.model.Resident] with
>>>>> identifier [1]: not found
>>>>>      [junit]  
>>>>> org.springframework.orm.ObjectRetrievalFailureException:
>>>>> Object of class [at.carenet.model.Resident] with identifier [1]:  
>>>>> not
>>>>> found
>>>>>      [junit]     at
>>>>> at.carenet.dao.hibernate.ResidentDaoHibernate.getResident
>>>>> (ResidentDaoHibernate.java:13)
>>>>>      [junit]     at at.carenet.dao.ResidentDaoTest.testSaveResident
>>>>> (ResidentDaoTest.java:29)
>>>>>      [junit]     at
>>>>> org.springframework.test.ConditionalTestCase.runBare
>>>>> (ConditionalTestCase.java:69)
>>>>>
>>>>>
>>>>>      [junit] Test at.carenet.dao.ResidentDaoTest FAILED
>>>>>
>>>>> BUILD FAILED
>>>>> /Users/bernd/Projects/carenet/build.xml:269: The following error
>>>>> occurred while executing this line:
>>>>> /Users/bernd/Projects/carenet/build.xml:540: Unit tests failed. For
>>>>> error messages, check the log files in
>>>>>                  /Users/bernd/Projects/carenet/build/test/data  
>>>>> or run
>>>>> "ant test-reports"
>>>>>                  to generate reports at /Users/bernd/Projects/
>>>>> carenet/
>>>>> build/test/reports.
>>>>>
>>>>>
>>>>> i checked if the id of the object created in test 1 is 1 and it
>>>>> seemed so when calling resident.getId() after dao.getResident()
>>>>> could it be that due to the rollback after test 1 the object is
>>>>> removed from the dabase so there is no object in the database with
>>>>> identifier 1 or what else could cause this error?
>>>>>
>>>>> bernd
>>>>>
>>>>> ------------------------------------------------------------------- 
>>>>> --
>>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>>
>>>>>
>>>>>
>>>>
>>>> -- 
>>>> View this message in context: http://www.nabble.com/testSave-fails%
>>>> 3A-ObjectRetrievalFailureException-tf2944871s2369.html#a8297472
>>>> Sent from the AppFuse - User mailing list archive at Nabble.com.
>>>>
>>>> -------------------------------------------------------------------- 
>>>> -
>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>>
>>>
>>
>> -- 
>> View this message in context: http://www.nabble.com/testSave-fails% 
>> 3A-ObjectRetrievalFailureException-tf2944871s2369.html#a8299945
>> Sent from the AppFuse - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/testSave-fails%3A-ObjectRetrievalFailureException-tf2944871s2369.html#a8368421
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to