11

i have a table with id field type BIGINT in MySQL

in hibernate object, i use java Long type for this field

but when run program, it throw exception: Expected: class java.lang.Long, got class java.lang.Integer

how to map MySQL BINGINT datatype in hibernate ?

JochenJung
  • 7,183
  • 12
  • 64
  • 113
QuanNH
  • 319
  • 1
  • 6
  • 22

2 Answers2

14

but when run program, it throw exception: Expected: class java.lang.Long, got class java.lang.Integer

Using a Long for a BIGINT is correct and the above error suggests that you are somehow passing an Integer where a Long is expected somewhere in your code. Double check your code.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
6

Does it help if you add a columnDefinition like columnDefinition = “bigint(20)″ to your mapping parameters?

mosterme
  • 61
  • 1
  • i use hibernate xml config file, & dont know how to config columnDefinition param :| – QuanNH Jul 23 '10 at 07:45
  • I'm sorry but how could this possibly help? – Pascal Thivent Jul 23 '10 at 08:08
  • Sometimes hibernate can not figure out how to correctly map the sql-type, but you are right, in that case the error message looks slightly different. Caused by: org.hibernate.HibernateException: Wrong column type in TEST.EXAMPLE for column FOO. Found: long, expected: integer – mosterme Jul 23 '10 at 08:41