我有一个带有
postgresql
列和javaJSOB
应用程序的spring jdbc
表。
但是当我尝试保存一个实体时,我得到了这个错误:
Caused by: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [INSERT INTO "complex" ("complex_id", "name") VALUES (?, ?)];
nested exception is org.postgresql.util.PSQLException: ERROR: relation "complex" does not exist
看起来
jdbc
认为complex
是一个单独的表,但实际上这个值应该只写到jsob
列。
我的
postgresql
桌子:
CREATE TABLE development
(
id TEXT PRIMARY KEY,
complex JSONB,
developer JSONB,
comment TEXT,
created_at TIMESTAMP NOT NULL
)
我的实体:
@Table(name = "development")
public class Development {
@Id
private String id;
private Complex complex;
private Developer developer;
private String comment;
@CreatedDate
private Instant createdAt;
}
资料库:
public interface DevelopmentRepository extends PagingAndSortingRepository<Development, String> {
}
我尝试保存实体的类:
@Component
public class JdbcDevelopmentAdapter implements CreateDevelopmentPort {
private final DevelopmentRepository repository;
@Override
public Development create(Development development) {
return save(development);
}
private Development save(Development development) {
return repository.save(development);
}
}
我试图将其实体存储在
jsonb
列中的类:
@Data
@Accessors(chain = true)
public class Apartment {
private String apartmentId;
private String name;
}
@Data
@Accessors(chain = true)
public class Developer {
private String developerId;
private String name;
}