2

Here is the exception - pastebin

Caused by: java.sql.SQLException: Unknown Parameter: 13
    at com.google.cloud.sql.jdbc.ParameterMetadata.getParameterType(ParameterMetadata.java:45)
    at org.hibernate.type.EnumType.nullSafeSet(EnumType.java:121)
    at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:155)
    at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2705)
    at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2682)
    at org.hibernate.persister.entity.AbstractEntityPersister$4.bindValues(AbstractEntityPersister.java:2863)
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
    ... 111 more

Enum's in my hibernate mapping -

<property name="userStatus" column="user_status" insert="true" update="true" index="true">
  <type name="org.hibernate.type.EnumType">
    <param name="enumClass">com.tutorial.enums.UserStatus</param>
    <param name="type">12</param>
  </type>
</property>
<property name="userType" column="user_type" insert="true" update="true" index="true">
  <type name="org.hibernate.type.EnumType">
    <param name="enumClass">com.tutorial.enums.UserType</param>
    <param name="type">12</param>
  </type>
</property>

My entity has UserType and UserStatus as enums. Hibernate is not able to convert enums properly. Should I switch back to hibernate 3 because in another project(with hibernate 3)I had my own custom type and it was working perfectly fine. I'm right now using hibernate 4.1.7.

1 Answer 1

2

Add

<param name="useNamed"></param>

and it should work fine.

<property name="userType" column="user_type" insert="true" update="true" index="true">
   <type name="org.hibernate.type.EnumType">
     <param name="enumClass">com.tutorial.enums.UserType</param>
     <param name="type">12</param>
     <param name="useNamed"></param>
   </type>
</property>

EDIT:

<param name="useNamed"></param>

must be there, but if you leave it blank then Enums will be serialized as Ordinals which is not very helpful if you do manual work on database, so if you want to get names then it must be

 <param name="useNamed">true</param>
Sign up to request clarification or add additional context in comments.

3 Comments

Now I see that you asked that same question earlier and I already answered there but I already answer here as well so let's leave it be...
I'm not getting any error now but none of the enum values are getting populated in the mysql table.
And when I set it's value to true it gives me 'data truncated for column' error. While my table definition is absolutely correct. I guess this version of hibernate is very buggy and am trying out ebean.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.