3 Replies Latest reply on May 8, 2006 12:21 PM by cyril.joui

    set of Attributes as member of an entytybean

    micho

      Hello,

      I want to store a selection of a given set of Attributes in an entitybean.

      I definded an enumeration Attributes:

      public enum Attributes
      { Attribut1,
      Attribut2,
      Attribut3,
      Attribut4,
      }

      and tried to define an embedded Attribute in the entityabean

      @Embedded
      private Set attributes;

      Unfortunately, this didnot work.
      Any ideas?

        • 1. Re: set of Attributes as member of an entytybean
          sunfire

          Since enum is a fixed set of attributes I don't think it would make much sens to save it into a DB. So why persist something that does not change at runtime and is part of your code?
          Usualy you only want to save the value on an enum attribute inside of an Entity and this would look somthing like this

          @Entity
          public class Storage {
          
           public enum StorageType { STUFF, MORE_STUFF, OTHER_STUFF }
          
           @Enumerated(EnumType.STRING)
           private StorageType storageType;
          
          }
          This would create a field of whatever String type is in your DB implementation and would store values like "STUFF" or "OTHER_STUFF" in it for the Entity.
          Hope this helps

          • 2. Re: set of Attributes as member of an entytybean
            micho

            I want vo store any possibel set of attribut combinations.


            @Entity
            public class Storage {

            public enum StorageType { STUFF, MORE_STUFF, OTHER_STUFF }

            @Enumerated(EnumType.STRING)
            private Set storageType;

            void add (StorageType stuff)
            { storageType.add(stuff); }

            }


            ..
            public static void main(String[] args)
            {
            Storage storage = new Storage();

            storage.add(StorageType.STUFF);
            storage.add(StorageType.MORE_STUFF);

            ...

            • 3. Re: set of Attributes as member of an entytybean

              I am not sure you can do this ..
              You may use another entity for StorageType and use ManyToMany ?

              I think you can use enum fonctionnality.
              Let's look at enum sets :
              >
              Enum sets also provide a rich, typesafe replacement for traditional bit flags:

              EnumSet.of(Style.BOLD, Style.ITALIC)
              <

              see : http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html

              Good luck !