3.4 KiB
3.4 KiB
title, source_type, status, branch, related_projects, tags, created, updated
| title | source_type | status | branch | related_projects | tags | created | updated | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| error / spring-jpa-postgres-lob-oid-cast-2026-06-23 | error-note | raw | feature-build-release-supply-chain-contract |
|
|
2026-06-23 | 2026-06-23 |
PostgreSQL column cannot be cast automatically to type oid during Hibernate ddl-auto update
Parent
- Parent branch note: raw/branch-notes/feature-build-release-supply-chain-contract
Symptoms
During application boot, Hibernate threw a warning/exception when trying to run auto-DDL commands:
2026-06-23 14:32:01.573 WARN [main] o.h.t.s.i.ExceptionHandlerLoggedImpl - GenerationTarget encountered exception accepting command : Error executing DDL "alter table if exists outbox_event alter column payload set data type oid" via JDBC [ERROR: column "payload" cannot be cast automatically to type oid
Hint: You might need to specify "USING payload::oid".]
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table if exists outbox_event alter column payload set data type oid" via JDBC [ERROR: column "payload" cannot be cast automatically to type oid
Hint: You might need to specify "USING payload::oid".]
Root Cause
- The Flyway migration script
V3__outbox_event.sqldefines thepayloadcolumn astext:payload text NOT NULL, - The Java entity
OutboxEventEntity.javadeclared the property using@Lob:@Lob @Column(name = "payload", nullable = false, updatable = false) private String payload; - In Hibernate (especially when using a PostgreSQL dialect), a
@Lobannotation on aStringproperty maps it to the JDBC typeTypes.BLOB/CLOB, which in PostgreSQL defaults to theoid(Object Identifier) type rather than standardtext. - When
ddl-autois set toupdate(typical in dev/local environments), Hibernate compares its internal mapping (oid) with the actual DB column type (text). Finding a mismatch, it generates an alter-table command to change the data type tooid. - PostgreSQL rejects this conversion implicitly because converting a text column to
oidrequires a custom cast expression (USING payload::oid).
Solution
Remove the @Lob annotation from payload in OutboxEventEntity.java and map it using a portable long varchar hint instead of an RDBMS-specific column definition:
@JdbcTypeCode(SqlTypes.LONGVARCHAR)
@Column(name = "payload", nullable = false, updatable = false)
private String payload;
Why it works
@JdbcTypeCode(SqlTypes.LONGVARCHAR)maps theStringproperty to standard JDBCLONGVARCHARtype.- On PostgreSQL, the Hibernate dialect translates
LONGVARCHARtotext. - On other databases (like Oracle or H2), it maps to
cloborvarcharwith maximum capacity, preserving vendor-neutrality. - Because both Flyway and Hibernate now agree that the column type is
text, no DDL alterations are triggered during startup.
Verification & Outcomes
Local Verification
- Replaced the annotation in
OutboxEventEntity.java. - Ran
./gradlew cleanto ensure all stale compilation caches are invalidated. - 기동 검증:
./gradlew :app-bootstrap:bootRun실행 결과, DDL alteration 경고 및 오류 없이 완전히 깨끗하게 기동되었습니다:2026-06-23 14:41:40.748 INFO [main] d.c.bootstrap.CaSkeletonApplication - Started CaSkeletonApplication in 4.193 seconds