membersound
membersound

Reputation: 86747

SQL insert with enums?

how can I insert SQL value for eg:

class MyEnum {
    FOO, BAR
}

which is later mapped to a MyEnum property = MyEnum.FOO;

How can I INSERT into XX (property) values ('FOO')?

When I try it like this, I get:

Data conversion error converting "'FOO' (MYENUM INTEGER)";

Upvotes: 2

Views: 1866

Answers (2)

Alex Navasardyan
Alex Navasardyan

Reputation: 536

you have to map java enum to hibernate. this and this might help.

Upvotes: 1

Nitin Chhajer
Nitin Chhajer

Reputation: 2339

you got to convert your enum into a hibernate user type and change the mapping of the column to the UserType class. take a look at this Reference

Upvotes: 0

Related Questions