I created a simple Spring Boot application with JPA connecting to a Postgres database. I want to store large text files in the database and for that I am using the @Lob annotation on a String attribute, which JPA successfully maps to a Text type in Postgres. However, when I persist an entity to the database, the text contents are always saved as an unrelated integer. A varchar is persisted as expected. Please see the snippets below. What am I missing here?
(some lines omitted for simplification purposes)
SampleEntity.java:
@Entity
public class SampleEntity {
@GeneratedValue(strategy = GenerationType.AUTO)
@Id
private Long id;
@Column
private String varcharTest;
@Lob
private String textTest;
...
}
SampleRepository.java
@Repository
public interface SampleRepository extends JpaRepository<SampleEntity, Long> {
}
My application.yml:
spring:
datasource:
platform: postgres
url: jdbc:postgresql://myserver:32432/postgres
username: postgres
password: <password>
Application.java:
@SpringBootApplication
public class Application {
private static ApplicationContext ctx;
public static void main(String[] args) throws Exception {
ctx = SpringApplication.run(Application.class, args);
SampleEntity se = new SampleEntity();
se.setTextTest("abc1234");
se.setVarcharTest("xyz5678");
SampleRepository sampleRepo = ctx.getBean(SampleRepository.class);
sampleRepo.save(se);
