Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't think hibernate provides a way to manage the mappings the way you're describing. You can create your own <code>UserType</code> (<a href="https://community.jboss.org/wiki/Java5EnumUserType" rel="nofollow">https://community.jboss.org/wiki/Java5EnumUserType</a>) but every time you add a new enum value you will have to change the logic in the <code>UserType</code> to map the new field as well.</p> <p>The alternative will be to convert this into a one to many relationship. Your point is basically that if you want to add more fields you will have to change the signature of <code>listEntities</code> but also you will have to modify your table.</p> <p>So, instead you can create a table that will contain your entity types and have a @OneToMany` relationship to it from your entity. For example:</p> <p>Define your flags as required:</p> <pre><code>public enum Flags { EDITABLE, REVIEW_NEEDED, ACTIVE } </code></pre> <p>Create a one-to-many relationship to <code>EntityType</code>:</p> <pre><code>@Entity @Table( name="entity" ) public class Entity implements Serializable { @OneToMany(mappedBy = "entity") public Set&lt;EntityType&gt; getEntityTypes() { return entityTypes; } </code></pre> <p>And a many-to-one to <code>Entity</code>:</p> <pre><code>@Entity @Table( name="entityType" ) public class EntityType implements Serializable { @Id private Integer id; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "ENTITY_ID") private Entity entity; @Enumerated(EnumType.STRING) private Flag entityType; ... } </code></pre> <p>PD: Please note the code is just an example and is not complete or tested.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload