You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Cédric Pineau <pi...@codelutin.com> on 2003/08/21 10:06:39 UTC
JDO inheritance problem
Hello,
I'm trying to use OJB through JDO and have a problem with basic
inheritance between two persitent class :
I get "
class entities.Statute2 overrides final method .
java.lang.VerifyError: class entities.Statute2 overrides final
method .
at java.lang.ClassLoader.defineClass0(Native Method)
... "
at runtime when the classloader loads the Statute2 class.
Statute2 inherits from Statute (this actually a test drive :-) Here is
my code :
>>>>>>>>>>>>>> Statute :
package entities;
public class Statute {
protected int id;
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
/** default constructor */
public Statute() {}
/** full constructor */
public Statute(java.lang.String name) {
this.name = name;
}
protected java.lang.String name;
public java.lang.String getName() {
return this.name;
}
public void setName(java.lang.String name) {
this.name = name;
}
public String toString() {
return "Statute "+this.name+" (id = "+this.id+")";
}
}
>>>>>>>>>>>>>> Statute 2 :
package entities;
public class Statute2 extends Statute {
/** default constructor */
public Statute2() {}
/** full constructor */
public Statute2(java.lang.String name, String name2) {
this.name = name;
this.name2 = name2;
}
protected java.lang.String name2;
public java.lang.String getName2() {
return this.name2;
}
public void setName2(java.lang.String name2) {
this.name2 = name2;
}
public String toString() {
return "Statute "+this.name+" "+this.name2+" (id = "+this.id+")";
}
}
repository_user.xml :
<class-descriptor class="entities.Statute" table="STATUTE">
<extent-class class-ref="entities.Statute2" />
<field-descriptor name="id" column="ID" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"/>
<field-descriptor name="name" column="NAME" jdbc-type="VARCHAR"/>
</class-descriptor>
<class-descriptor class="entities.Statute2" table="STATUTE2">
<field-descriptor name="id" column="ID" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"/>
<field-descriptor name="name" column="NAME" jdbc-type="VARCHAR"/>
<field-descriptor name="name2" column="NAME2" jdbc-type="VARCHAR"/>
</class-descriptor>
entities.jdo (partial) :
...
<class name="Statute">
<extension vendor-name="ojb" key="table" value="Statute"/>
<field name="id">
<extension vendor-name="ojb" key="column" value="id"/>
</field>
<field name="name">
<extension vendor-name="ojb" key="column" value="name"/>
</field>
</class>
<class name="Statute2">
<extension vendor-name="ojb" key="table" value="Statute2"/>
<field name="name2">
<extension vendor-name="ojb" key="column" value="name2"/>
</field>
</class>
...
sql for table creation (postgresql) :
CREATE TABLE STATUTE (
ID INT PRIMARY KEY,
NAME TEXT
);
CREATE TABLE STATUTE2 (
ID INT PRIMARY KEY,
NAME TEXT,
NAME2 TEXT
);
I suppose I did something wrong but can't figure what.
I already tried to enhance only one of the two, to remove id and name
from Statute2 class-desciptor entry but...
Can someone light my way to the wonderful world of JDO ?
Thanks,
Cédric
--
Societe Code Lutin
2, rue Robert le Ricolais
BP 20446 44304 NANTES CEDEX 3
Tel 02.40.50.29.28, Fax 02.40.93.99.21
http://www.codelutin.com
--------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: JDO inheritance problem
Posted by Cédric Pineau <pi...@codelutin.com>.
On Thu, 21 Aug 2003 08:54:07 -0500
Ketan Gangatirkar <ja...@ketan.org> wrote:
> persistence-capable-superclass="A"
That's what I was missing !
Thank you !
I went a little further and ... got another (smaller, I think) problem
:
java.lang.ClassCastException
at org.apache.ojb.jdori.sql.OjbExtent.<init>(Unknown Source)
at org.apache.ojb.jdori.sql.OjbStoreManager.getExtent(Unknown
Source)
at com.sun.jdori.common.PersistenceManagerImpl.getExtent(Unknown
Source)
at com.sun.jdori.common.query.QueryImpl.checkCandidates(Unknown
Source)
at com.sun.jdori.common.query.QueryImpl.execute(Unknown Source)
at UCListAllStatutes.apply(UCListAllStatutes.java:38)
...
Statue2 get recorded in its own table correctly.
Statute also
But I can't list Statute the way I used to :
manager.currentTransaction().begin();
Query query = manager.newQuery(Statute.class);
Collection allStatutes = (Collection)query.execute();
The last line give me the exception.
Any idea about that ?
Cédric
--
Societe Code Lutin
2, rue Robert le Ricolais
BP 20446 44304 NANTES CEDEX 3
Tel 02.40.50.29.28, Fax 02.40.93.99.21
http://www.codelutin.com
--------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: JDO inheritance problem
Posted by Ketan Gangatirkar <ja...@ketan.org>.
Cédric,
You need to define the attribute persistent-capable-superclass in your
.jdo file for the sub-class. So if you have class A extends class B,
your .jdo file would have:
<class name="B" persistence-capable-superclass="A">
The JDORI enhancer creates final methods to access the persistent
attributes of the object. If it does not know that B is a subclass of
A, it will define them for both B and A, which will result in the error
you see. If A has an attribute z, then you should list it only in the
<class> section of A. Since B is a subclass of A, it will inherit the
getter/setters that JDORI creates for z. Only define B's unique
attributes in the <class> section for B. Like so:
<class name="A">
<field name="z">
<field name="y">
</class>
<class name="B" persistence-capable-superclass="A">
<field name="x">
</class>
Cédric Pineau wrote:
>
> Hello,
>
>
> I'm trying to use OJB through JDO and have a problem with basic
> inheritance between two persitent class :
> I get "
> class entities.Statute2 overrides final method .
> java.lang.VerifyError: class entities.Statute2 overrides final
> method .
> at java.lang.ClassLoader.defineClass0(Native Method)
> ... "
> at runtime when the classloader loads the Statute2 class.
>
> Statute2 inherits from Statute (this actually a test drive :-) Here is
> my code :
>
>
>>>>>>>>>>>>>>>Statute :
>
> package entities;
> public class Statute {
> protected int id;
> public int getId() {
> return this.id;
> }
> public void setId(int id) {
> this.id = id;
> }
>
>
> /** default constructor */
> public Statute() {}
> /** full constructor */
> public Statute(java.lang.String name) {
> this.name = name;
> }
>
>
> protected java.lang.String name;
> public java.lang.String getName() {
> return this.name;
> }
> public void setName(java.lang.String name) {
> this.name = name;
> }
>
>
> public String toString() {
> return "Statute "+this.name+" (id = "+this.id+")";
> }
> }
>
>
>>>>>>>>>>>>>>>Statute 2 :
>
> package entities;
> public class Statute2 extends Statute {
> /** default constructor */
> public Statute2() {}
> /** full constructor */
> public Statute2(java.lang.String name, String name2) {
> this.name = name;
> this.name2 = name2;
> }
>
>
> protected java.lang.String name2;
> public java.lang.String getName2() {
> return this.name2;
> }
> public void setName2(java.lang.String name2) {
> this.name2 = name2;
> }
>
> public String toString() {
> return "Statute "+this.name+" "+this.name2+" (id = "+this.id+")";
> }
> }
>
> repository_user.xml :
> <class-descriptor class="entities.Statute" table="STATUTE">
> <extent-class class-ref="entities.Statute2" />
> <field-descriptor name="id" column="ID" jdbc-type="INTEGER"
> primarykey="true" autoincrement="true"/>
> <field-descriptor name="name" column="NAME" jdbc-type="VARCHAR"/>
> </class-descriptor>
>
>
> <class-descriptor class="entities.Statute2" table="STATUTE2">
> <field-descriptor name="id" column="ID" jdbc-type="INTEGER"
> primarykey="true" autoincrement="true"/>
> <field-descriptor name="name" column="NAME" jdbc-type="VARCHAR"/>
> <field-descriptor name="name2" column="NAME2" jdbc-type="VARCHAR"/>
> </class-descriptor>
>
> entities.jdo (partial) :
> ...
> <class name="Statute">
> <extension vendor-name="ojb" key="table" value="Statute"/>
> <field name="id">
> <extension vendor-name="ojb" key="column" value="id"/>
> </field>
> <field name="name">
> <extension vendor-name="ojb" key="column" value="name"/>
> </field>
> </class>
> <class name="Statute2">
> <extension vendor-name="ojb" key="table" value="Statute2"/>
> <field name="name2">
> <extension vendor-name="ojb" key="column" value="name2"/>
> </field>
> </class>
> ...
>
> sql for table creation (postgresql) :
> CREATE TABLE STATUTE (
> ID INT PRIMARY KEY,
> NAME TEXT
> );
>
>
> CREATE TABLE STATUTE2 (
> ID INT PRIMARY KEY,
> NAME TEXT,
> NAME2 TEXT
> );
>
>
> I suppose I did something wrong but can't figure what.
> I already tried to enhance only one of the two, to remove id and name
> from Statute2 class-desciptor entry but...
>
> Can someone light my way to the wonderful world of JDO ?
> Thanks,
>
> Cédric
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org