bad value for type long: - Postgresql, Hibernate, Spring

被刻印的时光 ゝ 提交于 2019-12-04 01:38:12

I had a similiar problem but it was not related to the order of ID field in the database.

After some searching I found this pointing to the fact that Lobs in Hibernate are treated as OIDs unless otherwise specified.

That means Hibernate will try put a Lob into a Long a hence produce that exception PSQLException: Bad value for type long

The way to specify that the Lob is a to be treated as text is by annotating the field

@Lob
@Type(type = "org.hibernate.type.TextType")

when I created the table the column "name" happened to be the first. That's not good. Id must be the first column. If I change the order of columns it works fine...

At first I tried to set

@Column(columnDefinition = "text")

instead of @Lob annotation, as already mentioned here. It worked for me on PostgreSQL, but with error org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [htmlText] in table [Question]; found [clob (Types#CLOB)], but expecting [text (Types#VARCHAR)]

in my unit tests (on HSQLDB).

Then it tried

@Column(columnDefinition = "clob")

And it works well on both PostgreSQL and HSQLDB!

I faced smiler error and the reason was that I was having some characters other than integer in integer data type filed

e.g.- ,111 and 144- etc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!