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 Alen Ribic <al...@mweb.co.za> on 2003/06/02 15:48:30 UTC
Inheritance issue
Hi all
I have a bit of a problem with inheritance in my application when it comes
to storing persistent objects using OJB.
I am using Struts in combination with OJB.
What I have now is a JavaBean "User" and I have a direct subclass
"RegisterForm".
What I wanna do is use RegisterForm as my FormBean and at runtime I wish to
reference a User type reference and store that in my db. So, I would like to
reuse the setters/getters of my User bean where necessary for Struts
purpose. (Any form where user's setters/getters are needed)
My OJB XML repository contains mapping for User Bean to User relational
table.
So, now the problem is as follows:
...
User user = null;
user = (User)request.getAttribute("registerForm");
...
PersistenceBroker broker = null;
try {
broker = PersistenceBrokerFactory.
defaultPersistenceBroker();
broker.beginTransaction();
broker.store(user);
broker.commitTransaction();
} catch(Throwable exc) {
...
}
...
In the above code snippet, "request.getAttribute("registerForm");", returns
an instance of RegisterForm class. (Then I cast to User type...)
As soon as store(...) method is fired, ClassNotPersistenceCapableException
is thrown indicating that za.co.alen.struts.RegisterForm class is not found
in OJB Repository.
I need OJB system to reference RegisterForm classes direct superclass, in
this case User of course.
Any help on how I can overcome this problem will be much appreciated.
Thanks,
--Alen
Re: Inheritance issue
Posted by Alen Ribic <al...@mweb.co.za>.
thanks
----- Original Message -----
From: "Thomas Mahler" <th...@web.de>
To: "OJB Users List" <oj...@db.apache.org>
Sent: Monday, June 02, 2003 4:38 PM
Subject: Re: Inheritance issue
> Hi Alen,
>
> You have to tell OJB that there is an inheritance hierarchy.
> You do it by defining extents.
> There is an example for this in repository_junit.xml.
> Have a look at definitions for classes Article, BookArticle, CdArticle.
>
> cheers,
> Thomas
>
> Alen Ribic wrote:
> > Hi all
> >
> > I have a bit of a problem with inheritance in my application when it
comes
> > to storing persistent objects using OJB.
> >
> > I am using Struts in combination with OJB.
> > What I have now is a JavaBean "User" and I have a direct subclass
> > "RegisterForm".
> > What I wanna do is use RegisterForm as my FormBean and at runtime I wish
to
> > reference a User type reference and store that in my db. So, I would
like to
> > reuse the setters/getters of my User bean where necessary for Struts
> > purpose. (Any form where user's setters/getters are needed)
> > My OJB XML repository contains mapping for User Bean to User relational
> > table.
> >
> > So, now the problem is as follows:
> >
> > ...
> > User user = null;
> > user = (User)request.getAttribute("registerForm");
> > ...
> > PersistenceBroker broker = null;
> > try {
> > broker = PersistenceBrokerFactory.
> > defaultPersistenceBroker();
> > broker.beginTransaction();
> > broker.store(user);
> > broker.commitTransaction();
> > } catch(Throwable exc) {
> > ...
> > }
> > ...
> >
> > In the above code snippet, "request.getAttribute("registerForm");",
returns
> > an instance of RegisterForm class. (Then I cast to User type...)
> > As soon as store(...) method is fired,
ClassNotPersistenceCapableException
> > is thrown indicating that za.co.alen.struts.RegisterForm class is not
found
> > in OJB Repository.
> >
> > I need OJB system to reference RegisterForm classes direct superclass,
in
> > this case User of course.
> >
> > Any help on how I can overcome this problem will be much appreciated.
> >
> > Thanks,
> > --Alen
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: ojb-user-help@db.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
Re: Inheritance issue
Posted by Thomas Mahler <th...@web.de>.
Hi Alen,
You have to tell OJB that there is an inheritance hierarchy.
You do it by defining extents.
There is an example for this in repository_junit.xml.
Have a look at definitions for classes Article, BookArticle, CdArticle.
cheers,
Thomas
Alen Ribic wrote:
> Hi all
>
> I have a bit of a problem with inheritance in my application when it comes
> to storing persistent objects using OJB.
>
> I am using Struts in combination with OJB.
> What I have now is a JavaBean "User" and I have a direct subclass
> "RegisterForm".
> What I wanna do is use RegisterForm as my FormBean and at runtime I wish to
> reference a User type reference and store that in my db. So, I would like to
> reuse the setters/getters of my User bean where necessary for Struts
> purpose. (Any form where user's setters/getters are needed)
> My OJB XML repository contains mapping for User Bean to User relational
> table.
>
> So, now the problem is as follows:
>
> ...
> User user = null;
> user = (User)request.getAttribute("registerForm");
> ...
> PersistenceBroker broker = null;
> try {
> broker = PersistenceBrokerFactory.
> defaultPersistenceBroker();
> broker.beginTransaction();
> broker.store(user);
> broker.commitTransaction();
> } catch(Throwable exc) {
> ...
> }
> ...
>
> In the above code snippet, "request.getAttribute("registerForm");", returns
> an instance of RegisterForm class. (Then I cast to User type...)
> As soon as store(...) method is fired, ClassNotPersistenceCapableException
> is thrown indicating that za.co.alen.struts.RegisterForm class is not found
> in OJB Repository.
>
> I need OJB system to reference RegisterForm classes direct superclass, in
> this case User of course.
>
> Any help on how I can overcome this problem will be much appreciated.
>
> Thanks,
> --Alen
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>