-
1. Re: Can an EntityBean store a collection as an attribute?
dsundstrom Jun 30, 2002 3:11 PM (in response to alice)> My questions are:
>
> 1. Is it a good design choice?
No. Using a 1:N relationship and storing the comments in a separate table is a much better choice.
> 2. If yes, how do I store a "collection" in an
> entitybean? How will my setter and getter methods
> look like? (Remember each record in "Comments" table
> has a "collection" of comments).
This is the reason why it is better to use a separate table. If you want to store a collection in an entity, the cmp engine will serialize the collection and store it into the database in serialized form. This means that only a Java virtual machine can understand that data in your database, an you can't query against the comments using SQL or EJB-QL.
There are a lot of issues with the long term storage of serialized Java objects, and this is why Sun is moving towards XML for this job.