Issue Details (XML | Word | Printable)

Key: JDO-390
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Michelle Caisse
Reporter: Michelle Caisse
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
JDO

JPOX fails new test: change to projected Date field is reflected in the database

Created: 24/Jun/06 12:18 PM   Updated: 09/Apr/07 08:59 PM
Return to search
Component/s: tck2
Affects Version/s: JDO 2 maintenance release 1
Fix Version/s: JDO 2 maintenance release 1

Time Tracking:
Not Specified

Resolution Date: 09/Apr/07 08:59 PM


 Description  « Hide
Changes to a projected SCO should not be persisted to the data store. JPOX persists changes to a projected Date field in the new query.result.ProjectedSCODoesNotTrackChanges test.
   
 [java] 1) testDateField(org.apache.jdo.tck.query.result.ProjectedSCODoesNotTrackChanges)junit.framework.AssertionFailedError:
    [java] Expected Company instance not to be dirty; actual state is {persistent, transactional, dirty}
    [java] Expected projected field value is Fri Jun 23 21:53:29 PDT 2006; actual value is Wed Dec 31 16:02:03 PST 1969
    [java]
    [java] at org.apache.jdo.tck.JDO_Test.failOnError(JDO_Test.java:1052)
    [java] at org.apache.jdo.tck.query.result.ProjectedSCODoesNotTrackChanges.testDateField(ProjectedSCODoesNotTrackChanges.java:150)
    [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet
hodAccessorImpl.java:25)
    [java] at org.apache.jdo.tck.JDO_Test.runBare(JDO_Test.java:237)
    [java] at org.apache.jdo.tck.util.BatchTestRunner.doRun(BatchTestRunner.java:107)
    [java] at org.apache.jdo.tck.util.BatchTestRunner.start(BatchTestRunner.java:147)
    [java] at org.apache.jdo.tck.util.BatchTestRunner.main(BatchTestRunner.java:122)

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Andy Jefferson added a comment - 31/Mar/07 07:37 AM
Don't totally understand what this test is checking for :-
The comments say "This tests that when a Date field is selected and modified, there is no change in the owned instance.". I interpret this as saying that if I do a query and get a Date field back then if I change that Date, the object in the datastore that it relates to doesnt pick up that change. i.e the Date returned by the Query is not attached to anything.

OK, but the test actually gets a Date in that way and then sets the Date field of a Company object to be this returned Date and checks if the Company object is now dirty. JPOX has actually marked the Company as dirty (even though the date has the same value - which is a minor bug since we should avoid any unnessary datastore update, and I'll fix that), but it is not consistent with the comments of the test.

Should the test not be getting the Date back from the Query, then change the Date "time" value, and then retrieve the Company to see if it was updated ? (this would then be consistent with the other test in that file which does that with an embedded field).

Andy Jefferson added a comment - 31/Mar/07 07:49 AM
Some more comments ...
1. Test does a Query to get the Date of a Company object
2. Test then sets the Date field of the Company object to something else
3. Test then checks if the Company object is dirty. It fails if the Company is dirty ... but of course its dirty since its just had its date changed!
4. Test then does the Query again and compares the Date it got the first time with what it had this time, and fails if they are different. Well it changed the date of the Company in the meantime so of course they are different!

I personally would remove the "company.setFounded(testDate)" and instead update the "expectedDate" to a new value. That assumes, of course, that I understand the test correctly :-)

Erik Bengtson added a comment - 31/Mar/07 07:57 AM
The test checks whether a SCO field is transient. SCO wrapper instances should not be returned, but instead the java.util.Date.

Andy Jefferson added a comment - 31/Mar/07 08:01 AM
SCO wrappers are not returned ... its a java.util.Date that is returned :-P

Craig Russell added a comment - 31/Mar/07 07:01 PM
Andy is right. The test doesn't actually test what it's supposed to. Instead of
        comp.setFounded(testDate);
it should be something like
        testDate.setTime(123789L);

And then the tests should make sure that the company instance in memory is not dirty (test is ok here) and that the instance in the database still has the same Date as it did earlier, using an equals test.

There is a pretty good summary of the issue at http://mail-archives.apache.org/mod_mbox/db-jdo-dev/200606.mbox/%3cB60FB51F-43A4-43AD-A647-75283D6A969E@SUN.com%3e

The consensus is that if you project a Date from a query, the Date you get is not an owned SCO. It can be an SCO if your implementation chooses (the only requirement is that it is assignable to Date) but it cannot be owned.

The test method projects a Date, modifies it, and then verifies both that the instance in memory whence the projected Date was obtained is not modified, and that the instance in the database is not modified.

Craig Russell made changes - 31/Mar/07 07:01 PM
Field Original Value New Value
Assignee Andy Jefferson [ andy ] Michelle Caisse [ mcaisse ]
Repository Revision Date User Message
ASF #526916 Mon Apr 09 20:58:39 UTC 2007 mcaisse JDO-390
Files Changed
MODIFY /db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/query/result/ProjectedSCODoesNotTrackChanges.java

Michelle Caisse added a comment - 09/Apr/07 08:59 PM
Fixed with revision: 526916

Michelle Caisse made changes - 09/Apr/07 08:59 PM
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]