Hi Antonio,
if you want to map that with castor you need to use extends. Extends are
defined in mapping by:
<class name="playground.AAA2"
extends="playground.AAA2"
identity="a1 a2">
and your JAVA classes should be:
public class AAA1 {
Integer id1 = null;
Integer id2 = null;
String v1 = null;
....
}
public class AAA2 extends AAA1 {
String v2 = null;
....
}
Having said that support in castor 0.9.7 is a little tricky and has some
limitations. E.g. if you execute a OQL query like:
select o from playground.AAA1 o
you get a resultset with all objects being of class AAA1 even if they
should be AAA2. Because of this behaviour you need to load the AAA2
instance yourself by the identity extracted form the AAA1 instance.
If you urgently need that I suggest you to use the current CVS where
this problem is solved as we added support for polymorphism to castor
about 2 month ago. If you can wait about 2 weeks you will be able to
switch to new 0.9.9 release.
Regards
Ralf
antonio signore schrieb:
I have the following problem and not sure if it is supported by Castor:
2 tables:
AAA1 with multiple PK id1 and id2 and v that is a VARCHAR
AAA2 with multiple PK a1 and a2 that are FK to AAA1.id1 and AAA1.id2 and
v that is a VARCHAR
AAA1 contains also a filed aaa2 of type AAA2.
The mapping is:
<class name="playground.AAA1" identity="id1 id2" >
<cache-type type="count-limited"/>
<map-to table="AAA1"/>
<field name="id1" type="integer">
<sql name="id1" type="integer" dirty="check"/>
</field>
<field name="id2" type="integer">
<sql name="id2" type="integer" dirty="check"/>
</field>
<field name="v" type="string">
<sql name="v" type="varchar" dirty="check"/>
</field>
<field required="false" name="aaa2" type=" playground.AAA2">
<sql many_key="a1 a2" />
</field>
</class>
<class name="playground.AAA2" identity="a1 a2" >
<cache-type type="count-limited"/>
<map-to table="AAA2"/>
<field name="a1" type="integer">
<sql name="a1" type="integer" dirty="check"/>
</field>
<field name="a2" type="integer">
<sql name="a2" type="integer" dirty="check"/>
</field>
<field name="v" type="string">
<sql name="v" type="varchar" dirty="check"/>
</field>
</class>
The JAVA classes are :
public class AAA1
{
Integer id1 = null;
Integer id2 = null;
String v = null;
AAA2 aaa2 = null;
....
and
public class AAA2
{
Integer a1 = null;
Integer a2 = null;
String v = null;
....
The OQL I'm trying to execute is the following:
"select obj from playground.AAA1"
The error I get is generated by the following generated SQL:
10:23:33,281 INFO CastorDataLayer: CastorException =
org.exolab.castor.jdo.PersistenceException: Nested error:
java.sql.SQLException:
Invalid column name 'id1'. while executing
SELECT "AAA1"."id1","AAA1"."id2","AAA1"."v","AAA2"."a1","AAA2"."a2" FROM
"AAA2","AAA1"
WHERE "AAA1"."id1"*="AAA2"."id1" AND "AAA1"."id2"*="AAA2"."id2": Invalid
column name 'id1'.
That is obviously wrong because it should be (I guess):
SELECT "AAA1"."id1","AAA1"."id2","AAA1"."v","AAA2"."a1","AAA2"."a2" FROM
"AAA2","AAA1"
WHERE "AAA1"."id1"*="AAA2"."a1" AND "AAA1"."id2"*="AAA2"."a2"
Can somebody help me finding a solution to my problem?
Thanks
Antonio Signore
--
Syscon Ingenieurbüro für
Meß- und Datentechnik GmbH
Ralf Joachim
Raiffeisenstraße 11
D-72127 Kusterdingen
Germany
Tel. +49 7071 3690 52
Mobil: +49 173 9630135
Fax +49 7071 3690 98
Email: [EMAIL PROTECTED]
Web: www.syscon-world.de
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------