1 Reply Latest reply on Feb 21, 2006 6:38 PM by epbernard

    mapping with primitive types

    zauberlehrling

      I have question concerning mappings in EJB3. I found examples with mappings, where the values are entity beans. I would like to define a mapping with primitive types like java.lang.String. My example is the following:

      package bean;

      import java.io.Serializable;
      import java.util.Map;
      import javax.persistence.*;
      import org.hibernate.annotations.CollectionOfElements;

      @Entity
      public class Test implements Serializable {

      private int id;
      private Map<java.lang.String,java.lang.String> texts;

      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      public int getId()
      {
      return id;
      }

      public void setId(int id)
      {
      this.id = id;
      }

      @CollectionOfElements
      @MapKey
      public Map<java.lang.String,java.lang.String> getTexts()
      {
      return texts;
      }

      public void setTexts(Map<java.lang.String,java.lang.String> texts)
      {
      this.texts = texts;
      }
      }

      and I use jboss-4.0.4RC1 with the "all" configuration. While deploying I
      get with the mentioned settings the following errors:

      19:17:28,812 WARN [ServiceController] Problem starting service persistence.units:unitName=tempdb
      java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      ....
      Caused by: org.hibernate.AnnotationException: Associated class not found: java.lang.String
      at org.hibernate.cfg.annotations.MapBinder.bindKeyFromAssociationTable(MapBinder.java:65)
      at org.hibernate.cfg.annotations.MapBinder.access$000(MapBinder.java:32)
      at org.hibernate.cfg.annotations.MapBinder$1.secondPass(MapBinder.java:55)
      at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:35)
      at org.hibernate.cfg.annotations.CollectionBinder.bind(CollectionBinder.java:331)
      at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1296)
      at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:629)
      ...

      Please could you tell me how to define a mapping with Strings as values?

      Thanks in advance!