6 Replies Latest reply on Jun 20, 2007 12:00 PM by christian.bauer

    How to persist entities that have arrays or collections of e

    grettke_spdr

      How to persist entities that have arrays or collections of enums?

      It doesn't seem to work out of the box.

        • 1. Re: How to persist entities that have arrays or collections
          pmuir

          This is a JPA/hibernate question, please ask on the relevant forum

          • 2. Re: How to persist entities that have arrays or collections
            grettke_spdr

             

            "pete.muir@jboss.org" wrote:
            This is a JPA/hibernate question, please ask on the relevant forum


            Hi Pete, I guess the question is "Does Seam support this out of the box?". In other words can I do this without writing a converter or any custom code?

            I want to know if I am wasting my time trying to make this work.

            No one replies in the Hibernate boards, anyway.

            • 3. Re: How to persist entities that have arrays or collections
              christian.bauer

              It works just fine and I don't see what it has to do with any entityconverter. If your entity has a mapped and persistent collection, it will be managed as part of the mapped entity.

              • 4. Re: How to persist entities that have arrays or collections
                grettke_spdr

                 

                "christian.bauer@jboss.com" wrote:
                It works just fine and I don't see what it has to do with any entityconverter. If your entity has a mapped and persistent collection, it will be managed as part of the mapped entity.


                Hey Christian,

                My post about entityConverter dealt with my lack of understanding about the role of entityConverter. I was trying to do a selectMany using a collection of ENUMs. ENUMs aren't supported out of the box for this task, so I used this one:

                http://shrubbery.mynetgear.net/wiki/Select_lists_with_Seam#Select_from_an_enum

                Once I got to that point where I could populate that array of enums, and tried to persist it, it failed. I don't recall the error, but I will set it up again to reproduce it if it is worth your file.

                If you are saying that "entities should persist arrays or lists of ENUMs just like they already do with classes" then that answers my questions.

                Perhaps I should be asking, do enum types need to be configured as entities? I was hoping we could just configure them to be persisted as ordinals.

                There is information about doing this with Hibernate, but everyone is pointing to user types.

                Unfortunately I don't have any Hibernate expert friends which is why I disturb you guys so frequently. Bless you guys thanks for your time, seriously, you make many things so much easier.

                • 5. Re: How to persist entities that have arrays or collections
                  christian.bauer

                  If an entity class has a property of type Enum, you can use @Enumerated(EnumType.STRING). Ordinal representation is even the default. So this is basic Java Persistence and you need to do nothing except put a property in an entity class that is of Enum type.

                  There is no support for storing a collection of Enum objects - the point of an enumeration is really that you pick _one_. I can imagine that you can use @CollectionOfElements and a Hibernate UserType that maps the collection element. This is outside of the scope of JPA.

                  I don't know any other documentation that would get you as close to this goal as my book although there is no direct example of doing this in it. There is a UserType for enumerations in it and examples how to use @CollectionOfElements.

                  • 6. Re: How to persist entities that have arrays or collections
                    christian.bauer

                    The UserType is also in this code: http://caveatemptor.hibernate.org/