admin管理员组文章数量:1394147
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?
1 Answer
Reset to default 1Ok, 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.
本文标签: javaHow to change existing persisted data from LOB to TEXTStack Overflow
版权声明:本文标题:java - How to change existing persisted data from LOB to TEXT? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744703762a2620715.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论