Use PostgreSQL CLob in Hibernate

Source: Internet
Author: User

When running an integration test, the following PSQLException error occurs:

The corresponding model hasStringType fields are marked@ Lob, Hibernate converts itCLob.

HoweverCLobEDB'sGetClobMethod calledGetLongAnd then tryCLobConvertLong.

No edb source code, so I had to find the pg source code on Github and find the method that caused this error.ToLong, Which is consistent with my judgment.

(It is unwise to output errors in Chinese after localization. Searching for "wrong Long" may not be able to find anything at all, but searching for "bad value for type Long" is totally different .)

Why callGetLongWhat about it?

In this article, we found that Large objects are stored in other locations and directly store their pointers (that is, a long Object ). If the type is text, the text is directly stored instead of the pointer, so the conversion fails.

It is worth noting that,CLobThe corresponding columns in PostgreSQL should not be text columns, so do not be misled.

The solution is simple. Delete it in the model.@ LobAnnotation for Hibernate to callGetStringInsteadGetCLobYou can.

Or keep@ LobAnnotation, and then add one@ Org. hibernate. annotations. Type (type = "org. hibernate. type. StringClobType ").

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.