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 Johan Andersson <jo...@lovefilm.se> on 2008/02/18 12:24:18 UTC
Mapping a List (or Set) with OJB.
Greetings!
Say I have a class MyClass it looks like this:
public class MyClass {
private int id;
private String name;
private List<Integer> myIntegers = new ArrayList<Integer>;
/* getters and setters omitted ... */
}
What options do I have if I want to persist this class using OJB?
The List<Integer> is causing me problems since it is not a pesistent
entity class.
Requirements impede me from just putting it into one field and use a
IntList2VarcharFieldConversion.
Requrements want me to have the List<Integer> data in a separate
database table.
But I just cant figure out how to map this.
Here's my tables (I am using MySQL):
CREATE TABLE `MY_CLASS` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `ITEMS` (
`my_class_id` int(10) unsigned NOT NULL,
`item_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`my_class_id`, `item_id`)
);
Thankful for any suggestions.
/JOHAN
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Mapping a List (or Set) with OJB.
Posted by Armin Waibel <ar...@apache.org>.
Hi Johan,
Johan Andersson wrote:
> Greetings!
>
> Say I have a class MyClass it looks like this:
>
> public class MyClass {
> private int id;
> private String name; private List<Integer> myIntegers = new
> ArrayList<Integer>;
>
> /* getters and setters omitted ... */
> }
>
>
> What options do I have if I want to persist this class using OJB?
>
> The List<Integer> is causing me problems since it is not a pesistent
> entity class.
> Requirements impede me from just putting it into one field and use a
> IntList2VarcharFieldConversion.
> Requrements want me to have the List<Integer> data in a separate
> database table.
> But I just cant figure out how to map this.
Sorry, to have the List<Integer> data in a separate database table is
not supported by OJB. In this case OJB expect a persistence capable
class e.g. Items.
regards,
Armin
>
> Here's my tables (I am using MySQL):
> CREATE TABLE `MY_CLASS` (
> `id` int(10) unsigned NOT NULL auto_increment,
> `name` varchar(255) NOT NULL,
> PRIMARY KEY (`id`)
> );
> CREATE TABLE `ITEMS` (
> `my_class_id` int(10) unsigned NOT NULL,
> `item_id` int(10) unsigned NOT NULL,
> PRIMARY KEY (`my_class_id`, `item_id`)
> );
>
>
> Thankful for any suggestions.
> /JOHAN
>
> ---------------------------------------------------------------------
> 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