Enum type field on JPA entity

Posted: August 7, 2013 in web

Entity

...
@Column(name = "Company", nullable = false)
@Enumerated(EnumType.STRING)
private Company company;
...

Enum

public enum Company {
    BMW("ultimate driving machine"), HONDA("honda motors");

    private final String name;

    Company(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public static Map<String, Company> getMap() {
        Map<String, Company> hashMap = new LinkedHashMap<>();
        for (Company company : Company.values()) {
            hashMap.put(company.name, company);
        }
        return hashMap;
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s