ObjectDB ObjectDB

enumeration table? how to on pure jpa?


Hello , I've relational db , and there is some table named enumerations with , some key and values.We will migrate to objectdb.
Our problem is , we want to store some keys and values for global application configs.


tablename : enumeration

table rows:

key            value

serverPort     4444
username       test
password       test
pictureCount   588


Is there any JPA annotation that can handle all those easiest way ?

Like this:


public class Enumerations {
    //Field binding possible like below ? 
    private String serverName;
    private String username;
    private Integer serverPort;

    public final String getServerName() {
        return serverName;
    public final void setServerName(String serverName) {
        this.serverName = serverName;

So , when i make set , get servername I will directly set or get config from server.

I know there is no field value on Column annotation but i need solution like that on pure JPA if possible.

Fastest clear way...

I've looked some other annotations but i could not find any solution like this.


If you use an Enumerations class as demonstrated above, you will have a single entity object that you can retrieve easily by:

    Enumerations e = em.createQuery(
        "SELECT e FROM Enumerations", Enumerations.class).getSingleResult();


Alternatively you can define a special entity class, e.g. GlobalProperty with two String fields key and value, and store your global properties using multiple entity objects of that class.

The key field could also be set as a primary key for fast and simple access by find:

    String serverName = em.find(GlobalProperty.class, "serverName").getValue();


ObjectDB Support

Sometimes doing these by hand forces users some mistakes when configuration count increase much.
It would be good to natively add into ObjectDB like me shown on top.That helps us utilizing autocomplete from IDE and minimizing error string mapping.


You may use your code at #1 with the query at #2.

Since you asked for a pure JPA solution - adding an extension to ObjectDB will not help.

ObjectDB Support


To post on this website please sign in.