views:

411

answers:

0

I am using Hibernate annotations and entity manager (JPA) with HSQLDB. So I have an entity with an enum field:

@Enumerated(EnumType.STRING)
@Column(name = "access_level")
public AccessLevel getAccessLevel() {
    return accessLevel;
}

Where AccessLevel is an enum. I can persist this, detach, and then query and everything is as it should be. However, once I close the EntityManagerFactory and everything flushes out to disk and then start again, this field always comes up null.

When I query the database with the HSQLDB Manager, everything is there and the column in this table contains the name of the enum element as it should. However, when I query, the entity has everything except this field is always null.

I am trying to avoid the user type business and keep it simple. What confuses me is that it is only after closing the EntityManagerFactory that this happens. I can persist and detach the object and then merge, query, find or whatever using other EntityManagers and transactions and the enum is handled correctly.

Any clue would be helpful.