How to handle choice field with JPA 2, Hibernate 3.5

Posted by phmr on Stack Overflow See other posts from Stack Overflow or by phmr
Published on 2010-05-01T14:01:36Z Indexed on 2010/05/01 14:07 UTC
Read the original article Hit count: 266

Filed under:
|
|
|

I have an entity with Integer attributes that looks like this in proto code:

class MyEntity:
    String name
    Integer frequency
    Integer type

    def getFrequency()
    def getType()

get* accessors return strings according to this table.

value(type) HumanReadableString(type)
  1             BSD
  2             Apache
  3             GPL

min frequency         max frequency    HumanReadableString(frequency)
    0                     1000                rare
    1000                  2000              frequent
    2001                  3000                sexy

It should be possible to get all possible values that an attribute can take, example:

getChoices(MyEntity, "type") returns ("rare", "frequent", "sexy")

It should be possible to get the bound value from the string:

getValue(MyEntity, "frequency", "sexy") returns (2000,3000)

© Stack Overflow or respective owner

Related posts about java

Related posts about jpa2.0