Java – hibernate with long text columns for Oracle and PostgreSQL
I'm trying to make an entity use Oracle (11.2) and PostgreSQL (9.4) in spring boot (1.4.4) applications
My entity contains a long text field (more than 4000 characters) The appropriate data type in Oracle is CLOB, and the corresponding type in PostgreSQL is text
I can make it work with PostgreSQL
@Column(name = "LONG_TEXT",columnDeFinition="TEXT") private String longText;
However, because CLOB requires @ lob annotation, Oracle will fail in the sleep verification phase
The following code applies to Oracle
@Lob @Column(name = "LONG_TEXT") private String longText;
However, the following exception occurs when reading from PostgreSQL this time:
Stack overflow suggestions executes queries in transactions Ignoring the suspicious requirements for calling transactions in select queries, adding @Transactional to the query method is not helpful.
Any idea is welcome
Solution
Our solution is @ lob and @ transactional
The main problem is that the @ transactional annotation is placed, resulting in psqlexception Once fixed, we can use these two types of DB