impossibl / pgjdbc-ng

A new JDBC driver for PostgreSQL aimed at supporting the advanced features of JDBC and Postgres
https://impossibl.github.io/pgjdbc-ng
Other
600 stars 107 forks source link

pgjdbc-ng + Hibernate / JPA #550

Open FrostbittenKing opened 3 years ago

FrostbittenKing commented 3 years ago

Hi, we discovered a problem persisting byte data into a postgresql text column after switching to pgjdbc-ng from the classical postgres jdbc driver. I located the issue in the JavaTypeMapping class which tries to resolve a Blob via the loid type (which doesn't exist in postgresql). I found an old bug report regarding lobs, which seems to have been resolved somehow (https://github.com/impossibl/pgjdbc-ng/issues/7), but the complicated oid aliasing seems to cause a stackoverflow exception because this somehow makes pgjdbc-ng drop into recursive attempts to try to decode the data. As far as i can tell, value="blob.type=oid" this property doesn't exist anymore, so this doesn't help either. I'm confused from the report / discussion why the oid type was changed to loid in JavaTypeMapping.java (compared to JDBCTypeMapping, which resolves blob/clob to oid instead of loid). Is this a bug / forgotten change? I finally fixed the issue by creating an alias via the following postgresql statement: create domain loid as oid which makes the driver + hibernate behave exactly like the classic jdbc driver. Another thing which I find frustrating is that, although it was stated that the oid behavior will be documented in the wiki (which was stated 2013), there is zero mentioning of loid or oid in the documentation. I debugged the code for two days to fix the issue (which I thought would be a breeze). Would it be finally possible to document all this stuff? Also I'm not sure if this is the correct fix (creating a domain aliasing loid to oid).

Thx for all.

kdubb commented 3 years ago

Hi @FrostbittenKing thanks for reporting, the issues you reference are probably woefully out of date with regard to documentation (we don't even use the wiki any longer).

Can you provide a small reproducer project using Maven or Gradle that I can run and debug? Clearly this should work and needs to be fixed.

FrostbittenKing commented 3 years ago

Holy cow your response was fast :). Yeah, I will try to cook something up at the weekend. I Understand the github wiki is not used, I found the documentation (which I thought to be in a more or less recent state) https://impossibl.github.io/pgjdbc-ng/docs/current/user-guide/ - this doesn't mention anything about the oid/loid stuff. But TLDR: Jpa Entity with following property; @javax.persistence.Column @javax.persistence.Lob private byte[] data;

Postgresql: create corresponding table + data property type: 'TEXT'.

FrostbittenKing commented 3 years ago

https://github.com/FrostbittenKing/pgjdbc-demo-bug Here is the requested sample project. Details are listed in the readme.

There is an Integration test using a postgresql testcontainer which asserts that no exception is thrown, which obviously failed in this case.

FrostbittenKing commented 3 years ago

Any news? Does this example help?

FrostbittenKing commented 3 years ago

Bump. Don't know what I should do else here.