Actually, I want to avoid proprietary annotations--standards are very
important for this project. What I ended up with is shown here:
package org.eremite.corm.party;
>
> import org.eremite.corm.Archetype;
>
> import javax.persistence.Entity;
> import javax.persistence.GeneratedValue;
> import javax.persistence.Id;
>
> @Entity
> public class Property extends Archetype {
>
> @Id
> @GeneratedValue
> private long ID;
>
> public Property() {}
>
> public Property(String name, String desc) {
> setName(name);
> setDescription(desc);
> }
>
> public long getID() {
> return ID;
> }
>
> public void setID(long ID) {
> this.ID = ID;
> }
>
> public String getKey() {
> return getName();
> }
>
> public void setKey(String key) {
> setName(key);
> }
>
> public String value() {
> return getDescription();
> }
>
> public void setValue(String val) {
> setDescription(val);
> }
>
> public boolean equals(Object that) {
> if(that instanceof Property) {
> return this.getKey().equals(((Property)that).getKey());
> }
> return false;
> }
>
> public int hashCode() {
> return (getKey() + value()).hashCode();
> }
>
> public String toString() {
> return getKey() + " = " + value();
> }
> }
>
The Archetype class is show here:
package org.eremite.corm;
>
> import javax.persistence.Id;
> import javax.persistence.MappedSuperclass;
> import java.io.Serializable;
>
> @MappedSuperclass
> public class Archetype implements Serializable {
>
> private String name = "";
> private String description = "";
>
> public Archetype() {}
>
> public String getName(){
> return name;
> }
>
> public void setName(String name) {
> this.name = name;
> }
>
> public String getDescription(){
> return description;
> }
>
> public void setDescription(String description) {
> this.description = description;
> }
> }
>
Then, I keep a Set of these Property objects with a simple
@OneToMany(cascade=CascadeType.ALL) annotation, and have some methods for
correctly adding and removing to and from the set. Presto. It's great,
because now I have a standardized Properties table in the database that I
can pore over, and I can use the properties like this in any of my other
classes.
Great to know about the proprietary annotation option, though--someone out
there will find it useful.
Cheers,
--
Alexander R. Saint Croix
On Dec 31, 2007 12:56 PM, Patrick Linskey <[EMAIL PROTECTED]> wrote:
> What about the proprietary @PersistentMap annotation? I'd guess that
> this will do exactly what you're looking for (table with three
> columns, one for the fk, one for the key, and one for the value).
>
> -Patrick
>
> On Dec 31, 2007 1:37 AM, Alexander Saint Croix
>
> <[EMAIL PROTECTED]> wrote:
> > In response to my own question:
> >
> > I found, buried near the bottom of the JPA spec, the section on the
> > @MapKey annotation, and think that I'd be better off implementing
> > another entity for this purpose rather than relying on the default
> > behavior of the java.util.Map. In addition to a key, I need to map
> > TWO values, so it makes little sense to use a Map.
> >
> > Cheers,
> > --
> > Alex