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 Thomas Papke <we...@thopap.de> on 2004/11/27 17:42:38 UTC

Question from a beginner

Hello to OJB-Users,

I started to learn how to use OJB with a little example, but here i have 
a problem. Maybe anyone could help.

I have 3 classes with a few attributes:
abstract class benutzer;
    - string name
    - string vname
    - int benutzer_id
    - string passwort
    - string benutzername
    - string ojbConcreteClass
class stduser extends benutzer;
    - no extra attributes yet
class admin extends benutzer;
    - bollean benutzer;

I want to map the conrete objects stduser and admin to the 3 tables: 
benutzer, stduser and admin. In table benutzer, i want to have the 
attributes of benutzer and in stduser/admin the special attributes.

Everything works fine if benutzer is not abstract. If it is set to 
abstract i got the following error if i want to store a stduser:

Can't create new base class object for 'de.ba.studi.chtp.model.Benutzer'

Maybe anybody could help. I can't find a docu how to map classes extended from a abstract class.


Thanks, Thomas

Here my mapping xml:
<class-descriptor
    class="de.ba.studi.chtp.model.Benutzer"
    table="Benutzer"
>
    <extent-class class-ref="de.ba.studi.chtp.model.Admin" />
    <extent-class class-ref="de.ba.studi.chtp.model.Stduser" />
    <field-descriptor
        name="benutzer_id"
        column="benutzer_id"
        jdbc-type="INTEGER"
        autoincrement="true"
        primarykey="true"
    />
    <field-descriptor
        name="name"
        column="name"
        jdbc-type="VARCHAR"
        length="254"
    />
    <field-descriptor
        name="vname"
        column="vname"
        jdbc-type="VARCHAR"
        length="254"
    />
    <field-descriptor
        name="passwort"
        column="passwort"
        jdbc-type="VARCHAR"
        length="254"
    />
    <field-descriptor
        name="benutzername"
        column="benutzername"
        jdbc-type="VARCHAR"
        length="254"
    />
    <field-descriptor
        name="ojbConcreteClass"
        column="CLASS_NAME"
        jdbc-type="VARCHAR"
    />
</class-descriptor>

<class-descriptor
    class="de.ba.studi.chtp.model.Admin"
    table="Admin"
>
    <field-descriptor
        name="benutzer_id"
        column="benutzer_id"
        jdbc-type="INTEGER"
        primarykey="true"
        autoincrement="true"
    />
    <field-descriptor
        name="produkte"
        column="produkte"
        jdbc-type="BIT"
    />
    <field-descriptor
        name="benutzer"
        column="benutzer"
        jdbc-type="BIT"
    />
    <reference-descriptor name="super"
        class-ref="de.ba.studi.chtp.model.Benutzer"
        auto-retrieve="true"
        auto-update="true"
        auto-delete="true"
    />
</class-descriptor>

<class-descriptor
    class="de.ba.studi.chtp.model.Stduser"
    table="Stduser"
>
    <field-descriptor
        name="benutzer_id"
        column="benutzer_id"
        jdbc-type="INTEGER"
        primarykey="true"
        autoincrement="true"
    />
    <reference-descriptor name="super"
        class-ref="de.ba.studi.chtp.model.Benutzer"
        auto-retrieve="true"
        auto-update="true"
        auto-delete="true"
    />
</class-descriptor>



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Question from a beginner

Posted by Thomas Papke <we...@thopap.de>.
Hi....

This was my fault to declare name as PK. Only ID is necessary and now it 
works.

Thanks a lot,
Thomas

Armin Waibel schrieb:

> Hi Thomas,
>
> you are using a compound PK (id, name), so the reference need to know 
> about both PK values of the main object (you only declared one FK 
> 'inId'). Why did you declare 'name' as primary key field? The 
> auto-increment PK field id will be unique.
>
> regards,
> Armin
>
> Thomas Papke wrote:
>
>> Thanks for help .... @ Thomas Dudziak
>>
>> I have a Object called "Produktgruppe". In each of this there is a 
>> Collection of Produktgruppe.
>> For this i have a table called "Produktgruppe" with rows: Id, Inid, name
>> In "inid" i will store the reference to the group over it (selfjoin 
>> between inid and id) and null if it is one of the master groups. So 
>> for example i could have main groups with cars and computer und it 
>> car e.g. ford and opel,...
>>
>> The saving of data works fine ... here an example of a table:
>> +-----+----------+------+
>> | id  | name     | inid |
>> +-----+----------+------+
>> |  21 | testkat  | NULL |
>> |  41 | neuKat   | NULL |
>> |  81 | asdasdf  | NULL |
>> | 181 | blubber  | NULL |
>> | 201 | blubber2 |   41 |
>> | 221 | test3    |   41 |
>> +-----+----------+------+
>>
>> here i have 4 main groups an in group "neuKat" 2 groups called 
>> blubber2 and test3.
>>
>> I have set auto-retrieve= true! So i think if i load the neuKat 
>> Object, i also retrieve the 2 groups blubber2 and test3 in the 
>> collection of neuKat. But i did not work???
>>
>> Thanks, Thomas
>>
>> Here my Deskriptor of Produktgruppe:
>> <class-descriptor
>>    class="de.ba.studi.chtp.model.Produktgruppe"
>>    table="Produktgruppe"
>>    auto-retrieve="true"
>>  >
>>    <field-descriptor
>>        name="id"
>>        column="id"
>>        jdbc-type="INTEGER"
>>        primarykey="true"
>>        autoincrement="true"
>>    >
>>    </field-descriptor>
>>    <field-descriptor
>>        name="inId"
>>        column="inId"
>>        jdbc-type="INTEGER"
>>    >
>>    </field-descriptor>
>>    <field-descriptor
>>        name="name"
>>        column="name"
>>        jdbc-type="VARCHAR"
>>        primarykey="true"
>>    >
>>    </field-descriptor>
>>    <collection-descriptor
>>       name="produktgruppen"
>>       element-class-ref="de.ba.studi.chtp.model.Produktgruppe"
>>       orderby="inId"
>>       sort="DESC"
>>       auto-retrieve="true"
>>       auto-update="true"
>>    >
>>       <inverse-foreignkey field-ref="inId"/>
>>    </collection-descriptor>
>> </class-descriptor>
>>
>> Thomas Dudziak schrieb:
>>
>>> Thomas Papke wrote:
>>>
>>>> Hello to OJB-Users,
>>>>
>>>> I started to learn how to use OJB with a little example, but here i 
>>>> have a problem. Maybe anyone could help.
>>>>
>>>> I have 3 classes with a few attributes:
>>>> abstract class benutzer;
>>>>    - string name
>>>>    - string vname
>>>>    - int benutzer_id
>>>>    - string passwort
>>>>    - string benutzername
>>>>    - string ojbConcreteClass
>>>> class stduser extends benutzer;
>>>>    - no extra attributes yet
>>>> class admin extends benutzer;
>>>>    - bollean benutzer;
>>>>
>>>> I want to map the conrete objects stduser and admin to the 3 
>>>> tables: benutzer, stduser and admin. In table benutzer, i want to 
>>>> have the attributes of benutzer and in stduser/admin the special 
>>>> attributes.
>>>>
>>>> Everything works fine if benutzer is not abstract. If it is set to 
>>>> abstract i got the following error if i want to store a stduser:
>>>>
>>>> Can't create new base class object for 
>>>> 'de.ba.studi.chtp.model.Benutzer'
>>>>
>>>> Maybe anybody could help. I can't find a docu how to map classes 
>>>> extended from a abstract class.
>>>
>>>
>>>
>>>
>>> I wonder, both of your super-references have no foreignkey, which 
>>> should not work (OJB should give you an error about this, if not 
>>> then there is a bug in the reading of the repository.xml). Try 
>>> adding a foreignkey pointing to benutzer_id.
>>> If that still doesn't work, then please post some more details (used 
>>> OJB version, exact stacktrace etc.).
>>>
>>> Tom
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>>
>
> ---------------------------------------------------------------------
> 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: Question from a beginner

Posted by Armin Waibel <ar...@apache.org>.
Hi Thomas,

you are using a compound PK (id, name), so the reference need to know 
about both PK values of the main object (you only declared one FK 
'inId'). Why did you declare 'name' as primary key field? The 
auto-increment PK field id will be unique.

regards,
Armin

Thomas Papke wrote:
> Thanks for help .... @ Thomas Dudziak
> 
> I have a Object called "Produktgruppe". In each of this there is a 
> Collection of Produktgruppe.
> For this i have a table called "Produktgruppe" with rows: Id, Inid, name
> In "inid" i will store the reference to the group over it (selfjoin 
> between inid and id) and null if it is one of the master groups. So for 
> example i could have main groups with cars and computer und it car e.g. 
> ford and opel,...
> 
> The saving of data works fine ... here an example of a table:
> +-----+----------+------+
> | id  | name     | inid |
> +-----+----------+------+
> |  21 | testkat  | NULL |
> |  41 | neuKat   | NULL |
> |  81 | asdasdf  | NULL |
> | 181 | blubber  | NULL |
> | 201 | blubber2 |   41 |
> | 221 | test3    |   41 |
> +-----+----------+------+
> 
> here i have 4 main groups an in group "neuKat" 2 groups called blubber2 
> and test3.
> 
> I have set auto-retrieve= true! So i think if i load the neuKat Object, 
> i also retrieve the 2 groups blubber2 and test3 in the collection of 
> neuKat. But i did not work???
> 
> Thanks, Thomas
> 
> Here my Deskriptor of Produktgruppe:
> <class-descriptor
>    class="de.ba.studi.chtp.model.Produktgruppe"
>    table="Produktgruppe"
>    auto-retrieve="true"
>  >
>    <field-descriptor
>        name="id"
>        column="id"
>        jdbc-type="INTEGER"
>        primarykey="true"
>        autoincrement="true"
>    >
>    </field-descriptor>
>    <field-descriptor
>        name="inId"
>        column="inId"
>        jdbc-type="INTEGER"
>    >
>    </field-descriptor>
>    <field-descriptor
>        name="name"
>        column="name"
>        jdbc-type="VARCHAR"
>        primarykey="true"
>    >
>    </field-descriptor>
>    <collection-descriptor
>       name="produktgruppen"
>       element-class-ref="de.ba.studi.chtp.model.Produktgruppe"
>       orderby="inId"
>       sort="DESC"
>       auto-retrieve="true"
>       auto-update="true"
>    >
>       <inverse-foreignkey field-ref="inId"/>
>    </collection-descriptor>
> </class-descriptor>
> 
> Thomas Dudziak schrieb:
> 
>> Thomas Papke wrote:
>>
>>> Hello to OJB-Users,
>>>
>>> I started to learn how to use OJB with a little example, but here i 
>>> have a problem. Maybe anyone could help.
>>>
>>> I have 3 classes with a few attributes:
>>> abstract class benutzer;
>>>    - string name
>>>    - string vname
>>>    - int benutzer_id
>>>    - string passwort
>>>    - string benutzername
>>>    - string ojbConcreteClass
>>> class stduser extends benutzer;
>>>    - no extra attributes yet
>>> class admin extends benutzer;
>>>    - bollean benutzer;
>>>
>>> I want to map the conrete objects stduser and admin to the 3 tables: 
>>> benutzer, stduser and admin. In table benutzer, i want to have the 
>>> attributes of benutzer and in stduser/admin the special attributes.
>>>
>>> Everything works fine if benutzer is not abstract. If it is set to 
>>> abstract i got the following error if i want to store a stduser:
>>>
>>> Can't create new base class object for 'de.ba.studi.chtp.model.Benutzer'
>>>
>>> Maybe anybody could help. I can't find a docu how to map classes 
>>> extended from a abstract class.
>>
>>
>>
>> I wonder, both of your super-references have no foreignkey, which 
>> should not work (OJB should give you an error about this, if not then 
>> there is a bug in the reading of the repository.xml). Try adding a 
>> foreignkey pointing to benutzer_id.
>> If that still doesn't work, then please post some more details (used 
>> OJB version, exact stacktrace etc.).
>>
>> Tom
>>
>> ---------------------------------------------------------------------
>> 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
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Question from a beginner

Posted by Thomas Papke <we...@thopap.de>.
Thanks for help .... @ Thomas Dudziak

I have a Object called "Produktgruppe". In each of this there is a 
Collection of Produktgruppe.
For this i have a table called "Produktgruppe" with rows: Id, Inid, name
In "inid" i will store the reference to the group over it (selfjoin 
between inid and id) and null if it is one of the master groups. So for 
example i could have main groups with cars and computer und it car e.g. 
ford and opel,...

The saving of data works fine ... here an example of a table:
+-----+----------+------+
| id  | name     | inid |
+-----+----------+------+
|  21 | testkat  | NULL |
|  41 | neuKat   | NULL |
|  81 | asdasdf  | NULL |
| 181 | blubber  | NULL |
| 201 | blubber2 |   41 |
| 221 | test3    |   41 |
+-----+----------+------+

here i have 4 main groups an in group "neuKat" 2 groups called blubber2 
and test3.

I have set auto-retrieve= true! So i think if i load the neuKat Object, 
i also retrieve the 2 groups blubber2 and test3 in the collection of 
neuKat. But i did not work???

Thanks, Thomas

Here my Deskriptor of Produktgruppe:
<class-descriptor
    class="de.ba.studi.chtp.model.Produktgruppe"
    table="Produktgruppe"
    auto-retrieve="true"
 >
    <field-descriptor
        name="id"
        column="id"
        jdbc-type="INTEGER"
        primarykey="true"
        autoincrement="true"
    >
    </field-descriptor>
    <field-descriptor
        name="inId"
        column="inId"
        jdbc-type="INTEGER"
    >
    </field-descriptor>
    <field-descriptor
        name="name"
        column="name"
        jdbc-type="VARCHAR"
        primarykey="true"
    >
    </field-descriptor>
    <collection-descriptor
       name="produktgruppen"
       element-class-ref="de.ba.studi.chtp.model.Produktgruppe"
       orderby="inId"
       sort="DESC"
       auto-retrieve="true"
       auto-update="true"
    >
       <inverse-foreignkey field-ref="inId"/>
    </collection-descriptor>
</class-descriptor>

Thomas Dudziak schrieb:

> Thomas Papke wrote:
>
>> Hello to OJB-Users,
>>
>> I started to learn how to use OJB with a little example, but here i 
>> have a problem. Maybe anyone could help.
>>
>> I have 3 classes with a few attributes:
>> abstract class benutzer;
>>    - string name
>>    - string vname
>>    - int benutzer_id
>>    - string passwort
>>    - string benutzername
>>    - string ojbConcreteClass
>> class stduser extends benutzer;
>>    - no extra attributes yet
>> class admin extends benutzer;
>>    - bollean benutzer;
>>
>> I want to map the conrete objects stduser and admin to the 3 tables: 
>> benutzer, stduser and admin. In table benutzer, i want to have the 
>> attributes of benutzer and in stduser/admin the special attributes.
>>
>> Everything works fine if benutzer is not abstract. If it is set to 
>> abstract i got the following error if i want to store a stduser:
>>
>> Can't create new base class object for 'de.ba.studi.chtp.model.Benutzer'
>>
>> Maybe anybody could help. I can't find a docu how to map classes 
>> extended from a abstract class.
>
>
> I wonder, both of your super-references have no foreignkey, which 
> should not work (OJB should give you an error about this, if not then 
> there is a bug in the reading of the repository.xml). Try adding a 
> foreignkey pointing to benutzer_id.
> If that still doesn't work, then please post some more details (used 
> OJB version, exact stacktrace etc.).
>
> Tom
>
> ---------------------------------------------------------------------
> 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: Question from a beginner

Posted by Thomas Dudziak <to...@first.fhg.de>.
Thomas Papke wrote:
> Hello to OJB-Users,
> 
> I started to learn how to use OJB with a little example, but here i have 
> a problem. Maybe anyone could help.
> 
> I have 3 classes with a few attributes:
> abstract class benutzer;
>    - string name
>    - string vname
>    - int benutzer_id
>    - string passwort
>    - string benutzername
>    - string ojbConcreteClass
> class stduser extends benutzer;
>    - no extra attributes yet
> class admin extends benutzer;
>    - bollean benutzer;
> 
> I want to map the conrete objects stduser and admin to the 3 tables: 
> benutzer, stduser and admin. In table benutzer, i want to have the 
> attributes of benutzer and in stduser/admin the special attributes.
> 
> Everything works fine if benutzer is not abstract. If it is set to 
> abstract i got the following error if i want to store a stduser:
> 
> Can't create new base class object for 'de.ba.studi.chtp.model.Benutzer'
> 
> Maybe anybody could help. I can't find a docu how to map classes 
> extended from a abstract class.

I wonder, both of your super-references have no foreignkey, which should 
not work (OJB should give you an error about this, if not then there is 
a bug in the reading of the repository.xml). Try adding a foreignkey 
pointing to benutzer_id.
If that still doesn't work, then please post some more details (used OJB 
version, exact stacktrace etc.).

Tom

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org