I am trying to save a pdf doc into my postgres 10.1 database using Hibernate. Below is my entity class.
@Entity
@Table(name = "FILEUPLOADS", schema="SomeSchema")
public class FileUploads{
//skipping other columns
@Lob
@Column(name="DOCDATA")
private byte[] docData;
}
This column is op type bytea in the postgres database.
As suggested by Authur here : similar issue, I created my custom implementation of postgres dialect like below.
@Configuration
public class TestDialect extends PostgreSQLDialect{
public TestDialect() {
super();
registerColumnType(Types.BLOB, "bytea");
}
}
Then inside my persistence.xml file , I am using this custom dialect
<property name="hibernate.dialect" value="com.digital.repository.TestDialect" />
Even after doing all this, I am getting below error
ERROR: column "DOCDATA" is of type bytea but expression is of type bigint
Hint: You will need to rewrite or cast the expression.
Position: 251
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2468)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2211)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:309)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:446)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:370)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:149)
at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:124)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
... 250 more
What else do I need to do in order to resolve this issue ?