[OJB-developers] ojb-0.7.343 - Single table inheritance still broken
Brought to you by:
thma
From: <Dal...@bd...> - 2002-02-13 03:25:37
|
I tried out my original code on OJB v0.7.343 and it appears single table inheritance is still be broken, or at least the bug I was encountering still exists. This specific bug shows up when you have descendent classes with *additional* fields. None of the OJB inheritance test cases have descendent classes with additional fields, so the bug never appears. This is strange, because having a bunch of classes with the exact number of fields is an unrealistic example of inheritance. Anyway, this bug has to do with having a descendent with additional fields, for example: class Foo { public int id; public String ojbConcreteClass; public String foo_value; .... } class Bar extends Foo { public Date bar_date; .... } TABLE FOOBAR (contents) ID CLASS_TYPE FOO_VALUE BAR_DATE ---- ---- ---- ---- 1 'Foo' 'A Foo' NULL 2 'Bar' 'A Bar' 02/03/2002 The repository.xml file maps Foo's fields to the first 3 columns, and Bar's fields to all 4 columns. If I try to map this type of class hierarchy with OJB and do a query for all instances of Foo, the first instance, which is *a Foo*, will get read in fine. However, when OJB goes to read in the Bar instance, I get this exception: [ojb.broker.accesslayer.RsIterator] ERROR: 3 3 at ojb.broker.accesslayer.RowReaderDefaultImpl.readObjectFrom(RowReaderDefaultImpl.java:72) at ojb.broker.accesslayer.RsIterator.getObjectFromResultSet(RsIterator.java:251) at ojb.broker.accesslayer.RsIterator.next(RsIterator.java:142) at plprototype2.tests.SingleTableInheritanceTest.testSingleTableInheritance(SingleTableInheritanceTest.java:81) at java.lang.reflect.Method.invoke(Native Method) at junit.framework.TestCase.runTest(TestCase.java:166) at junit.framework.TestCase.runBare(TestCase.java:140) 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:131) at junit.framework.TestSuite.runTest(TestSuite.java:173) at junit.framework.TestSuite.run(TestSuite.java:168) at junit.textui.TestRunner.doRun(TestRunner.java:74) at junit.textui.TestRunner.start(TestRunner.java:234) at junit.textui.TestRunner.main(TestRunner.java:112) at plprototype2.tests.SingleTableInheritanceTest.main(SingleTableInheritanceTest.java:39) [plprototype2.tests.SingleTableInheritanceTest] INFO: Inheritance query failed! java.util.NoSuchElementException at ojb.broker.accesslayer.RsIterator.next(RsIterator.java:151) at plprototype2.tests.SingleTableInheritanceTest.testSingleTableInheritance(SingleTableInheritanceTest.java:81) at java.lang.reflect.Method.invoke(Native Method) at junit.framework.TestCase.runTest(TestCase.java:166) at junit.framework.TestCase.runBare(TestCase.java:140) 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:131) at junit.framework.TestSuite.runTest(TestSuite.java:173) at junit.framework.TestSuite.run(TestSuite.java:168) at junit.textui.TestRunner.doRun(TestRunner.java:74) at junit.textui.TestRunner.start(TestRunner.java:234) at junit.textui.TestRunner.main(TestRunner.java:112) at plprototype2.tests.SingleTableInheritanceTest.main(SingleTableInheritanceTest.java:39) What's happening is that OJB is getting the definition for the number of fields to expect from Foo's mapping definition, but Foo has only been defined with 3 columns: ID, CLASS_TYPE, and FOO_VALUE. When it reads in the Bar instance, the RowReader returns an array of *4* columns: ID, CLASS_TYPE, FOO_VALUE, and BAR_DATE. When it tries to initialize the BAR_DATE value into the object, it goes past the 3 items in the Foo mapping definition and the system throws the java.util.NoSuchElementException. The only way inheritance works is if Foo and Bar had exactly the same fields, like this: class Foo { public int id; public String ojbConcreteClass; public String foo_value; public Date bar_date; .... } class Bar extends Foo { } But of course, this is not inheritance at all and contrary to how most real inheritance trees look. It is my suspicion that this may be a sticky bug to fix, but I hope I'm wrong. Anyway, let me know if this makes any sense or not. Dale Davis |