Solved Saving (persisting) Set<UUID> with Hibernate

Discussion in 'Spigot Plugin Development' started by robertlit, Jan 7, 2020.

Thread Status:
Not open for further replies.
  1. I am trying to save a set of uuids into a databse using hibernate.
    I want to save it like this: (Just an example, I actually save more data)
    --------------------------------------------------
    | table: groups |
    |------------------------------------------------ |
    | name | members |
    | ---------------------------------------------- |
    | test | (set of uuids) |
    | ------------------------------------------------ |
    And my class is something like this:
    Code (Java):
    @Entity
    @Table(name="groups")
    public class Group {
    @Column(name="name")
    String name;
    @Column(name="members")
    @ElementCollection
    Set<UUID> members;

    // Constructor, getters, setters
    }
    When I try to use the getter for the Set (Not when I get the object from the database), it throws a LazyInitializiationException (at the line of the getter method).
    The question is:
    What annotation should I use on the Set? (Or am I doing something completely wrong?)

    Thanks for your time.

    EDIT:
    When I use @OneToMany instead of @ElementCollection it throws AnnotationException on startup and says that java.util.UUID is not mapped
     
    #1 robertlit, Jan 7, 2020
    Last edited: Jan 7, 2020
  2. Is it me or there isn’t much code there?
     
  3. It's not about the code. It's a about what is the correct annotation to use to save a Set of UUIDs.
    I could post how I use Session#saveOrUpdate or how I build the SessionFactory but it won't help, since it has nothing to do with persisting the Set..
     
    #5 robertlit, Jan 7, 2020
    Last edited: Jan 7, 2020
Thread Status:
Not open for further replies.