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 Joose Vettenranta <jo...@iki.fi> on 2004/08/12 13:50:53 UTC
extent problem
Hi,
I'm having problems on using extent-class and extending java-classes..
I have like this:
class SuperChild extends Child {
private int age;
// getters and setters
}
class Child {
private int id;
private Parent parent;
private String name;
....
}
and in jdo-file I have:
<class name="SuperChild" identity-type="datastore"
persistence-capable-superclass="net.vettenranta.Child">
<field name="age" persistence-modifier="persistent">
<extension vendor-name="ojb" key="column" value="age" />
</field>
</class>
and it goes OK enhancing.
repository.xml:
<class-descriptor class="net.vettenranta.SuperChild" table="child">
<extent-class class-ref="net.vettenranta.Child" />
<field-descriptor name="age" nullable="false" default-fetch="true"
column="age" jdbc-type="INTEGER" />
</class-descriptor>
and result is:
org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException: Can
not init Identity for given object net.vettenranta.SuperChild@f7be4e
What could be wrong?
Thanks, Joose
--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * joose@iki.fi * +358 44 561 0270 *
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: extent problem
Posted by Thomas Dudziak <to...@first.fhg.de>.
Joose Vettenranta wrote:
> I solved it so, that I made 3 classes
>
> abstarct A
> B extends A
> C extends A
>
> and in code I call B or C not A. But still, B and C can't use same
> table name. Oh well, can't have everything. Problem is that now I
> have to change every class to use C instead of using A or B. What I
> would like to do like this:
>
> A
>
> B extends A
>
> and use B where B's extra stuff is needed and A where it's not
> needed. This way I can change just few files to use B and use A
> elsewhere. Now I have to change everything to use B.
This should work when you use the ojbConcreteClass strategy.
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: extent problem
Posted by Joose Vettenranta <jo...@iki.fi>.
Hi,
>> it seems that when I try to get Child it also get's SuperChild.. even
>> though I haven't said that it should get superchild. All I want is
>> to get just Child not superCHild.. Perhaps it's not possible to get
>> like this?
> You'll need to add a field called 'ojbConcreteClass' so that OJB knows
> which class to instantiate. Or you can super-references (in which case
> you don't need to duplicate the fields from Child in SuperChild in the
> repository file). See here for details on these strategies:
> http://db.apache.org/ojb/docu/guides/advanced-
> technique.html#Mapping+Inheritance+Hierarchies
I solved it so, that I made 3 classes
abstarct A
B extends A
C extends A
and in code I call B or C not A. But still, B and C can't use same
table name. Oh well, can't have everything. Problem is that now I have
to change every class to use C instead of using A or B. What I would
like to do like this:
A
B extends A
and use B where B's extra stuff is needed and A where it's not needed.
This way I can change just few files to use B and use A elsewhere. Now
I have to change everything to use B.
> Also I don't know whether two connections on the same database works.
> You might run into problems with the cache. You should definitly have
> a look at the different cache implementations provided with OJB:
Yes, this was a problem and solved in CVS.
- Joose
--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * joose@iki.fi * +358 44 561 0270 *
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: extent problem
Posted by Thomas Dudziak <to...@first.fhg.de>.
Joose Vettenranta wrote:
> Hi,
>
> it seems that when I try to get Child it also get's SuperChild.. even
> though I haven't said that it should get superchild. All I want is to
> get just Child not superCHild.. Perhaps it's not possible to get like
> this?
You'll need to add a field called 'ojbConcreteClass' so that OJB knows
which class to instantiate. Or you can super-references (in which case
you don't need to duplicate the fields from Child in SuperChild in the
repository file). See here for details on these strategies:
http://db.apache.org/ojb/docu/guides/advanced-technique.html#Mapping+Inheritance+Hierarchies
Also I don't know whether two connections on the same database works.
You might run into problems with the cache. You should definitly have a
look at the different cache implementations provided with OJB:
http://db.apache.org/ojb/docu/guides/objectcache.html
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: extent problem
Posted by Joose Vettenranta <jo...@iki.fi>.
Hi,
it seems that when I try to get Child it also get's SuperChild.. even
though I haven't said that it should get superchild. All I want is to
get just Child not superCHild.. Perhaps it's not possible to get like
this?
How about if I do Child interface
and SuperChild implements Child
and ChildImpl implements Child
could it work then?
- Joose
13.8.2004 kello 16:50, Thomas Dudziak kirjoitti:
Joose Vettenranta wrote:
>
>> I did this and it did not work.
>>
>> I get this:
>>
>> java.lang.NullPointerException
>> .......
>> java.lang.VerifyError: Class net.vettenranta.super.Child overrides
>> final method jdoReplaceFlags.()V
>> at java.lang.Class.forName0(Native Method)
>> at java.lang.Class.forName(Class.java:256)
>> at
>> org.apache.ojb.broker.util.ClassHelper.getClass(ClassHelper.java:30)
>> at
>> org.apache.ojb.broker.util.ClassHelper.getClass(ClassHelper.java:98)
>> at
>> org.apache.ojb.broker.metadata.RepositoryXmlHandler.startElement(Repos
>> it oryXmlHandler.java:199)
>> .....
>>
>> using: 1.0rc6
>
> Hmm, can't help you with the JDO stuff. You should post this error
> again (with the URL to your doc/tutorial) in a new thread with JDO in
> the message label (to attract the JDO experts).
>
> Tom
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * joose@iki.fi * +358 44 561 0270 *
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: extent problem
Posted by Joose Vettenranta <jo...@iki.fi>.
Hi,
I actually solved that JDO, problem but now my problems continue...
I made that superchild and child has same table name.. superchild uses
different connection than connection using child object.
But when I try to fetch Child, it actually tries to get SuperChild and
not Child -> SQL-error. Is this feature or have I done something wrong?
- Joose
13.8.2004 kello 16:50, Thomas Dudziak kirjoitti:
Joose Vettenranta wrote:
>
>> I did this and it did not work.
>>
>> I get this:
>>
>> java.lang.NullPointerException
>> .......
>> java.lang.VerifyError: Class net.vettenranta.super.Child overrides
>> final method jdoReplaceFlags.()V
>> at java.lang.Class.forName0(Native Method)
>> at java.lang.Class.forName(Class.java:256)
>> at
>> org.apache.ojb.broker.util.ClassHelper.getClass(ClassHelper.java:30)
>> at
>> org.apache.ojb.broker.util.ClassHelper.getClass(ClassHelper.java:98)
>> at
>> org.apache.ojb.broker.metadata.RepositoryXmlHandler.startElement(Repos
>> it oryXmlHandler.java:199)
>> .....
>>
>> using: 1.0rc6
>
> Hmm, can't help you with the JDO stuff. You should post this error
> again (with the URL to your doc/tutorial) in a new thread with JDO in
> the message label (to attract the JDO experts).
>
> Tom
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * joose@iki.fi * +358 44 561 0270 *
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: extent problem
Posted by Thomas Dudziak <to...@first.fhg.de>.
Joose Vettenranta wrote:
> I did this and it did not work.
>
> I get this:
>
> java.lang.NullPointerException
> .......
> java.lang.VerifyError: Class net.vettenranta.super.Child overrides
> final method jdoReplaceFlags.()V
> at java.lang.Class.forName0(Native Method)
> at java.lang.Class.forName(Class.java:256)
> at
> org.apache.ojb.broker.util.ClassHelper.getClass(ClassHelper.java:30)
> at
> org.apache.ojb.broker.util.ClassHelper.getClass(ClassHelper.java:98)
> at
> org.apache.ojb.broker.metadata.RepositoryXmlHandler.startElement(Reposit
> oryXmlHandler.java:199)
> .....
>
> using: 1.0rc6
Hmm, can't help you with the JDO stuff. You should post this error again
(with the URL to your doc/tutorial) in a new thread with JDO in the
message label (to attract the JDO experts).
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: extent problem
Posted by Joose Vettenranta <jo...@iki.fi>.
> You have to specify the extent-class as the first sub-tag of
> class-descriptor (see
> http://db.apache.org/ojb/docu/guides/repository.html#class-descriptor
> for details).
> Also, you have to duplicate all fields/references/collections from
> Child in SuperChild, currently they are not automatically 'inherited'
> in the descriptor of the sub class.
I did this and it did not work.
I get this:
java.lang.NullPointerException
.......
java.lang.VerifyError: Class net.vettenranta.super.Child overrides
final method jdoReplaceFlags.()V
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:256)
at
org.apache.ojb.broker.util.ClassHelper.getClass(ClassHelper.java:30)
at
org.apache.ojb.broker.util.ClassHelper.getClass(ClassHelper.java:98)
at
org.apache.ojb.broker.metadata.RepositoryXmlHandler.startElement(Reposit
oryXmlHandler.java:199)
.....
using: 1.0rc6
> I would recommend that you use the OJB and JDO Xdoclet modules (OJB
> module is part of OJB, the JDO module can be downloaded from
> http://xdoclet.sourceforge.net/xdoclet/index.html) to generate these
> two files, they will make things a lot easier for you.
Have to look into it.
- Joose
--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * joose@iki.fi * +358 44 561 0270 *
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: extent problem
Posted by Thomas Dudziak <to...@first.fhg.de>.
Joose Vettenranta wrote:
> Hi,
>
> everything else except SuperChild is in http://joose.iki.fi/ojb/
>
> SuperChild.java I already pasted.
> repository.xml:
>
> <descriptor-repository version="1.0" isolation-level="read-uncommitted">
> <jdbc-connection-descriptor jcd-alias="test"
> default-connection="true" platform="PostgreSQL"
> subprotocol="postgresql">
> <sequence-manager
> className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImp
> l"/>
> </jdbc-connection-descriptor>
> <class-descriptor class="net.vettenranta.Parent" table="PARENT">
> <field-descriptor name="id" primarykey="true"
> nullable="false" default-fetch="true" autoincrement="true"
> column="ID" sequence-name="parent_id_seq" jdbc-type="INTEGER"/>
> <field-descriptor name="name" default-fetch="true"
> column="NAME" jdbc-type="VARCHAR"/>
> <collection-descriptor name="childs"
> element-class-ref="net.vettenranta.Child" auto-retrieve="true"
> auto-delete="true" auto-update="true">
> <inverse-foreignkey field-ref="parent_id"/>
> </collection-descriptor>
> </class-descriptor>
> <class-descriptor class="net.vettenranta.Child" table="CHILDS">
> <field-descriptor name="id" primarykey="true"
> nullable="false" default-fetch="true" column="ID" jdbc-type="INTEGER"
> autoincrement="true" sequence-name="childs_id_seq" />
> <field-descriptor name="parent_id" nullable="false"
> default-fetch="true" column="PARENT_ID" jdbc-type="INTEGER"
> access="anonymous"/>
> <field-descriptor name="name" default-fetch="true"
> column="NAME" jdbc-type="VARCHAR"/>
> <reference-descriptor name="parent"
> class-ref="net.vettenranta.Parent">
> <foreignkey field-ref="parent_id" />
> </reference-descriptor>
> <extent-class class-ref="net.vettenranta.SuperChild" />
> </class-descriptor>
>
> <class-descriptor class="net.Vettenranta.SuperChild"
> table="CHILDS">
> <field-descriptor name="age" default-fetch="true"
> column="AGE" jdbc-type="INTEGER"/>
> </class-descriptor>
> </descriptor-repository>
You have to specify the extent-class as the first sub-tag of
class-descriptor (see
http://db.apache.org/ojb/docu/guides/repository.html#class-descriptor
for details).
Also, you have to duplicate all fields/references/collections from Child
in SuperChild, currently they are not automatically 'inherited' in the
descriptor of the sub class.
I would recommend that you use the OJB and JDO Xdoclet modules (OJB
module is part of OJB, the JDO module can be downloaded from
http://xdoclet.sourceforge.net/xdoclet/index.html) to generate these two
files, they will make things a lot easier for you.
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: extent problem
Posted by Joose Vettenranta <jo...@iki.fi>.
Hi,
everything else except SuperChild is in http://joose.iki.fi/ojb/
SuperChild.java I already pasted.
repository.xml:
<descriptor-repository version="1.0" isolation-level="read-uncommitted">
<jdbc-connection-descriptor jcd-alias="test"
default-connection="true" platform="PostgreSQL"
subprotocol="postgresql">
<sequence-manager
className="org.apache.ojb.broker.util.sequence.SequenceManagerNextValImp
l"/>
</jdbc-connection-descriptor>
<class-descriptor class="net.vettenranta.Parent" table="PARENT">
<field-descriptor name="id" primarykey="true"
nullable="false" default-fetch="true" autoincrement="true" column="ID"
sequence-name="parent_id_seq" jdbc-type="INTEGER"/>
<field-descriptor name="name" default-fetch="true"
column="NAME" jdbc-type="VARCHAR"/>
<collection-descriptor name="childs"
element-class-ref="net.vettenranta.Child" auto-retrieve="true"
auto-delete="true" auto-update="true">
<inverse-foreignkey field-ref="parent_id"/>
</collection-descriptor>
</class-descriptor>
<class-descriptor class="net.vettenranta.Child" table="CHILDS">
<field-descriptor name="id" primarykey="true"
nullable="false" default-fetch="true" column="ID" jdbc-type="INTEGER"
autoincrement="true" sequence-name="childs_id_seq" />
<field-descriptor name="parent_id" nullable="false"
default-fetch="true" column="PARENT_ID" jdbc-type="INTEGER"
access="anonymous"/>
<field-descriptor name="name" default-fetch="true"
column="NAME" jdbc-type="VARCHAR"/>
<reference-descriptor name="parent"
class-ref="net.vettenranta.Parent">
<foreignkey field-ref="parent_id" />
</reference-descriptor>
<extent-class class-ref="net.vettenranta.SuperChild" />
</class-descriptor>
<class-descriptor class="net.Vettenranta.SuperChild"
table="CHILDS">
<field-descriptor name="age" default-fetch="true"
column="AGE" jdbc-type="INTEGER"/>
</class-descriptor>
</descriptor-repository>
packages.jdo about SuperChild I already posted.
- Joose
--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * joose@iki.fi * +358 44 561 0270 *
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: extent problem
Posted by Thomas Dudziak <to...@first.fhg.de>.
Joose Vettenranta wrote:
> I have Child in jdo and it works ok
>
> but Superchild I told what kind it is:
>
> <class name="SuperChild" identity-type="datastore"
> persistence-capable-superclass="net.vettenranta.Child">
> <field name="age" persistence-modifier="persistent">
> <extension vendor-name="ojb" key="column" value="age" />
> </field>
> </class>
Could you post those two classes (at least with the fields/bean
properties that you declared in the repository file) and the jdo and
repository file ?
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: extent problem
Posted by Joose Vettenranta <jo...@iki.fi>.
12.8.2004 kello 15:03, Thomas Dudziak kirjoitti:
Joose Vettenranta wrote:
>
>> Clarifying myself:
>>
>> I want to have just one table in SQL called child. And software
>> eather uses Child or SuperChild (same table name in both).
>>
>> I tried moving (repository.xml) extent-class to superclass, but
>> didn't help.
> I don't know about JDO, but you probably have to specify both Child
> and SuperChild in both the jdo file and the repository file.
I have Child in jdo and it works ok
but Superchild I told what kind it is:
<class name="SuperChild" identity-type="datastore"
persistence-capable-superclass="net.vettenranta.Child">
<field name="age" persistence-modifier="persistent">
<extension vendor-name="ojb" key="column" value="age" />
</field>
</class>
- Joose
--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * joose@iki.fi * +358 44 561 0270 *
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: extent problem
Posted by Thomas Dudziak <to...@first.fhg.de>.
Joose Vettenranta wrote:
> Clarifying myself:
>
> I want to have just one table in SQL called child. And software eather
> uses Child or SuperChild (same table name in both).
>
> I tried moving (repository.xml) extent-class to superclass, but didn't
> help.
I don't know about JDO, but you probably have to specify both Child and
SuperChild in both the jdo file and the repository file.
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: extent problem
Posted by Joose Vettenranta <jo...@iki.fi>.
Clarifying myself:
I want to have just one table in SQL called child. And software eather
uses Child or SuperChild (same table name in both).
I tried moving (repository.xml) extent-class to superclass, but didn't
help.
- Joose
12.8.2004 kello 14:50, Joose Vettenranta kirjoitti:
Hi,
>
> I'm having problems on using extent-class and extending java-classes..
>
> I have like this:
>
> class SuperChild extends Child {
> private int age;
> // getters and setters
> }
>
> class Child {
> private int id;
> private Parent parent;
> private String name;
>
> ....
> }
>
> and in jdo-file I have:
> <class name="SuperChild" identity-type="datastore"
> persistence-capable-superclass="net.vettenranta.Child">
> <field name="age" persistence-modifier="persistent">
> <extension vendor-name="ojb" key="column" value="age" />
> </field>
> </class>
>
> and it goes OK enhancing.
>
> repository.xml:
> <class-descriptor class="net.vettenranta.SuperChild" table="child">
> <extent-class class-ref="net.vettenranta.Child" />
> <field-descriptor name="age" nullable="false" default-fetch="true"
> column="age" jdbc-type="INTEGER" />
> </class-descriptor>
>
> and result is:
>
> org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException:
> Can not init Identity for given object
> net.vettenranta.SuperChild@f7be4e
>
> What could be wrong?
>
> Thanks, Joose
>
> --
> "Always remember that you are unique, just like everyone else!"
> * http://iki.fi/joose/ * joose@iki.fi * +358 44 561 0270 *
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * joose@iki.fi * +358 44 561 0270 *
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: extent problem
Posted by Thomas Dudziak <to...@first.fhg.de>.
Joose Vettenranta wrote:
> Hi,
>
> I'm having problems on using extent-class and extending java-classes..
>
> I have like this:
>
> class SuperChild extends Child {
> private int age;
> // getters and setters
> }
>
> class Child {
> private int id;
> private Parent parent;
> private String name;
>
> ....
> }
>
> and in jdo-file I have:
> <class name="SuperChild" identity-type="datastore"
> persistence-capable-superclass="net.vettenranta.Child">
> <field name="age" persistence-modifier="persistent">
> <extension vendor-name="ojb" key="column" value="age" />
> </field>
> </class>
>
> and it goes OK enhancing.
>
> repository.xml:
> <class-descriptor class="net.vettenranta.SuperChild"
> table="child">
> <extent-class class-ref="net.vettenranta.Child" />
> <field-descriptor name="age" nullable="false"
> default-fetch="true" column="age" jdbc-type="INTEGER" />
> </class-descriptor>
>
> and result is:
>
> org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException:
> Can not init Identity for given object net.vettenranta.SuperChild@f7be4e
>
> What could be wrong?
The extent-class tag is a bit counter-intuitive because it specifies the
opposite direction of the Java extends/implements. So if you put
<extent-class class-ref="net.vettenranta.SuperChild" />
into the class descriptor for Child, you should be fine.
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org