How to store an ArrayList of Enum Values?

View: New views
5 Messages — Rating Filter:   Alert me  

How to store an ArrayList of Enum Values?

by t3_chris :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi!

I'am heavily using constructs like this to store Enum Values to the Database.

@Column(name = "customer_status", nullable = false)
@Enumerated(EnumType.STRING)
private CustomerStatus status;

Now, i am in need to store an ArrayList, or List or Collection of serveral of those Enum Values.
Can this be done with EclipseLink 1.0 ?

If yes, how?

I need something like:

@Enumerated(EnumType.STRING)
private ArrayList<CustomerStatus> customerStati;

How should the databasetable be designed for such thing?


Best Regards,
christian

Re: How to store an ArrayList of Enum Values?

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In EclipseLink you could use a @BasicCollection for this.  You would use a EnumTypeConverter to convert the Enum.  This mapping uses a separate table to store the values.

You could also just serialize the collection to a binary field, but this would not allow querying.

You could also instead change the Enum to a class and make it an Entity and define a OneToMany or ManyToMany to it.


t3_chris wrote:
Hi!

I'am heavily using constructs like this to store Enum Values to the Database.

@Column(name = "customer_status", nullable = false)
@Enumerated(EnumType.STRING)
private CustomerStatus status;

Now, i am in need to store an ArrayList, or List or Collection of serveral of those Enum Values.
Can this be done with EclipseLink 1.0 ?

If yes, how?

I need something like:

@Enumerated(EnumType.STRING)
private ArrayList<CustomerStatus> customerStati;

How should the databasetable be designed for such thing?


Best Regards,
christian

Re: How to store an ArrayList of Enum Values?

by Guy Pelletier :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Christian,

Yes this is possible. Your list will then need to be stored as a raw type as
this mapping will be serialized to the database.

Cheers,
Guy

----- Original Message -----
From: "t3_chris" <c.reiter@...>
To: <eclipselink-users@...>
Sent: Tuesday, August 19, 2008 4:48 PM
Subject: [eclipselink-users] How to store an ArrayList of Enum Values?


>
> Hi!
>
> I'am heavily using constructs like this to store Enum Values to the
> Database.
>
> @Column(name = "customer_status", nullable = false)
> @Enumerated(EnumType.STRING)
> private CustomerStatus status;
>
> Now, i am in need to store an ArrayList, or List or Collection of serveral
> of those Enum Values.
> Can this be done with EclipseLink 1.0 ?
>
> If yes, how?
>
> I need something like:
>
> @Enumerated(EnumType.STRING)
> private ArrayList<CustomerStatus> customerStati;
>
> How should the databasetable be designed for such thing?
>
>
> Best Regards,
> christian
> --
> View this message in context:
> http://www.nabble.com/How-to-store-an-ArrayList-of-Enum-Values--tp19051233p19051233.html
> Sent from the EclipseLink - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@...
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>

_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Parent Message unknown Re: How to store an ArrayList of Enum Values?

by Guy Pelletier :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Christian,

One other note, you can also map it using a BasicCollection.

See:
http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#How_to_Use_the_.40BasicCollection_Annotation

Cheers,
Guy

----- Original Message -----
From: "Guy Pelletier" <guy.pelletier@...>
To: "EclipseLink User Discussions" <eclipselink-users@...>
Sent: Wednesday, August 20, 2008 11:11 AM
Subject: Re: [eclipselink-users] How to store an ArrayList of Enum Values?


> Christian,
>
> Yes this is possible. Your list will then need to be stored as a raw type
> as this mapping will be serialized to the database.
>
> Cheers,
> Guy
>
> ----- Original Message -----
> From: "t3_chris" <c.reiter@...>
> To: <eclipselink-users@...>
> Sent: Tuesday, August 19, 2008 4:48 PM
> Subject: [eclipselink-users] How to store an ArrayList of Enum Values?
>
>
>>
>> Hi!
>>
>> I'am heavily using constructs like this to store Enum Values to the
>> Database.
>>
>> @Column(name = "customer_status", nullable = false)
>> @Enumerated(EnumType.STRING)
>> private CustomerStatus status;
>>
>> Now, i am in need to store an ArrayList, or List or Collection of
>> serveral
>> of those Enum Values.
>> Can this be done with EclipseLink 1.0 ?
>>
>> If yes, how?
>>
>> I need something like:
>>
>> @Enumerated(EnumType.STRING)
>> private ArrayList<CustomerStatus> customerStati;
>>
>> How should the databasetable be designed for such thing?
>>
>>
>> Best Regards,
>> christian
>> --
>> View this message in context:
>> http://www.nabble.com/How-to-store-an-ArrayList-of-Enum-Values--tp19051233p19051233.html
>> Sent from the EclipseLink - Users mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@...
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>
>

_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: How to store an ArrayList of Enum Values?

by t3_chris :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks a lot to all who posted here!

ATM i'm using the serialization solution. But i'll try to to switch over to @BasicCollection and @Converter later, i think, that will perform better.

Thanks guys,
 christian