java - How to change existing persisted data from LOB to TEXT? - Stack Overflow

I'm using Spring Boot 2.7 with builtin Hibernate and I have in an entity class like below:@Entity

I'm using Spring Boot 2.7 with builtin Hibernate and I have in an entity class like below:

@Entity
@Table(name = "style")
public class Style implements Serializable {

   ...
   
   @Column(name = "style_abstract")
   @Lob
   private String styleAbstract;
   
}

This style table's schema was populated by Liquibase with this changeSet:

<createTable tableName="style">
...
<column name="style_abstract" type="TEXT"/>
</changeSet>

Now, I realized that @Lob actually is not good idea but I have data already persisted in style table in Postgres.

How can I completely replace that large object in both Postgres and Hibernate?

I tried this in Spring JPA:

    @Column(name = "style_abstract", columnDefinition = "TEXT")
    @Type(type = ".hibernate.type.TextType")
    private String styleAbstract;

and with raw SQL in Postgres:

  ALTER TABLE style
            ALTER COLUMN style_abstract TYPE TEXT

but somehow when I deleting a Style object, then Hibernate still has error:

 WARN [2025-03-13 11:41:57] SqlExceptionHelper@137: SQL Error: 0, SQLState: 42704
 ERROR [2025-03-13 11:41:57] SqlExceptionHelper@142: ERROR: large object 0 does not exist
 ERROR [2025-03-13 11:41:57] ExceptionUtil@115: Caught an exception:
could not execute statement; SQL [n/a]; nested exception is .hibernate.exception.SQLGrammarException: could not execute statement
    at service.WMSRepositoryService$$EnhancerBySpringCGLIB$$d482f768.deleteStyleById(<generated>:-1)

Hibernate should not try to consider styleAbstract column as LOB any more when Style is deleted. I just wanted to remove that styleAbstract as a normal TEXT. How can I make it work like this?

I'm using Spring Boot 2.7 with builtin Hibernate and I have in an entity class like below:

@Entity
@Table(name = "style")
public class Style implements Serializable {

   ...
   
   @Column(name = "style_abstract")
   @Lob
   private String styleAbstract;
   
}

This style table's schema was populated by Liquibase with this changeSet:

<createTable tableName="style">
...
<column name="style_abstract" type="TEXT"/>
</changeSet>

Now, I realized that @Lob actually is not good idea but I have data already persisted in style table in Postgres.

How can I completely replace that large object in both Postgres and Hibernate?

I tried this in Spring JPA:

    @Column(name = "style_abstract", columnDefinition = "TEXT")
    @Type(type = ".hibernate.type.TextType")
    private String styleAbstract;

and with raw SQL in Postgres:

  ALTER TABLE style
            ALTER COLUMN style_abstract TYPE TEXT

but somehow when I deleting a Style object, then Hibernate still has error:

 WARN [2025-03-13 11:41:57] SqlExceptionHelper@137: SQL Error: 0, SQLState: 42704
 ERROR [2025-03-13 11:41:57] SqlExceptionHelper@142: ERROR: large object 0 does not exist
 ERROR [2025-03-13 11:41:57] ExceptionUtil@115: Caught an exception:
could not execute statement; SQL [n/a]; nested exception is .hibernate.exception.SQLGrammarException: could not execute statement
    at service.WMSRepositoryService$$EnhancerBySpringCGLIB$$d482f768.deleteStyleById(<generated>:-1)

Hibernate should not try to consider styleAbstract column as LOB any more when Style is deleted. I just wanted to remove that styleAbstract as a normal TEXT. How can I make it work like this?

Share Improve this question edited Mar 13 at 11:47 jonrsharpe 122k30 gold badges268 silver badges476 bronze badges asked Mar 13 at 11:28 Bằng RikimaruBằng Rikimaru 1,6052 gold badges29 silver badges57 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Ok, I wasted a lot of time, just because I didn't realize there are triggers on this table style. It can be viewed with psql:

\c DATABASENAME
\d tablename

It has trigger like this:

 trigger_delete_large_object_on_style_abstract BEFORE DELETE OR UPDATE ON style FOR EACH ROW EXECUTE FUNCTION lo_manage('style_abstract')  

Then, I removed this trigger with:

DROP TRIGGER trigger_delete_large_object_on_style_abstract ON style;  

and no more error when removing Style object by Spring JPA.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744703762a4588929.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信