users@glassfish.java.net

Re: Map as an entity column

From: Sanjeeb Kumar Sahoo <Sanjeeb.Sahoo_at_Sun.COM>
Date: Thu, 15 Mar 2007 22:31:45 +0530

Have you tried using a concrete implementation like HashMap instead of
using your own Map implementation? Since you may not like HashMap to be
in the public interface of the class, you may like to recode like this:

@Entity
public class Foo {
    // Use field based persistence and use HashMap as the field type.
    @Column(name="NAMES")
    @Basic
    private HashMap<String, String> names;

    public Map<String, String> getNames() {...}
    public void setNames(Map<String, String> names) {...}

}

I have not given serious thought to this approach, so I would like to
see pros and cons of this approach vs. others.

Thanks,
Sahoo

glassfish_at_javadesktop.org wrote:
> hey,
>
> I tried to set a MAP as an entity column as:
>
> @Column(name="NAMES")
> @Basic @Lob
> public Map<String, String> getNames() {
> return names;
> }
>
>
>
> But I get an exception that MAP cannot be serialized,
> I tried to create my own empty MAP class that extends Java's MAP and implements Serializable but then I get an exception that my map does not stands java generics rules,
>
>
> is there any way to map a MAP column of an entity?
>
>
> thanks.
> [Message sent by forum member 'demiant' (demiant)]
>
> http://forums.java.net/jive/thread.jspa?messageID=208125
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>