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

后端 未结 4 705
忘掉有多难
忘掉有多难 2021-02-07 00:29

I wanna store an entity(a String + an image) in PostgresQL using Spring MVC and Hibernate Here is my table. The image is supposed to be the type of oid.

CREATE T         


        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-07 01:10

    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")
    

提交回复
热议问题