Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PgArray does not implement Serializable Interface #726

Closed
MahatmaFatalError opened this issue Jan 5, 2017 · 8 comments
Closed

PgArray does not implement Serializable Interface #726

MahatmaFatalError opened this issue Jan 5, 2017 · 8 comments

Comments

@MahatmaFatalError
Copy link

Is there a reason why PgArray does not implement Serializable Interface?

Would be beneficial for some ORM caching mechanisms like MyBatis which relies on serializable objects

@davecramer
Copy link
Member

Likely because it is not required in the spec. Feel free to provide us with a Pull Request

@vlsi
Copy link
Member

vlsi commented Jan 5, 2017

@MahatmaFatalError , can you please clarify which MyBatis scenario relies serializable?

@MahatmaFatalError
Copy link
Author

MahatmaFatalError commented Jan 5, 2017

@vlsi please take a look at http://www.mybatis.org/mybatis-3/sqlmap-xml.html#cache as it states "A read-write cache will return a copy (via serialization) of the cached object." Thus, MyBatis caching must be disabled in order to avoid
org.apache.ibatis.cache.CacheException: Error serializing object. Cause: java.io.NotSerializableException when querying for a ResultSet containing an sql.Array.

@davecramer ok, I'will give it a try soon

@vlsi
Copy link
Member

vlsi commented Jan 5, 2017

Here's a quote from the spec

https://docs.oracle.com/javase/7/docs/api/java/sql/Array.html
By default, an Array value is a transaction-duration reference to an SQL ARRAY value. By default, an Array object is implemented using an SQL LOCATOR(array) internally, which means that an Array object contains a logical pointer to the data in the SQL ARRAY value rather than containing the ARRAY value's data

That means, the whole serializable concept of mybatis is flawed -- it should not try to access Array object outside of transaction.

I'm not sure if pgjdbc would be always to keep arrays serializable, so I'm inclined to decline the proposal.

@MahatmaFatalError
Copy link
Author

OK, to avoid this issue I could go by casting the Array to String within the query via array_to_string function and let the caller handle the ResultSet accordingly in order to leverage MyBatis caching capabilities (for Strings).

Just for interest, what would be a good caching mechanism on ORM side for sql.Array

@vlsi
Copy link
Member

vlsi commented Jan 6, 2017

Just for interest, what would be a good caching mechanism on ORM side for sql.Array

It could be like: fetch all the contents, create own implementation of sql.Array, hunt bugs when user tries to use cached array instance in statement.setArray

@MahatmaFatalError
Copy link
Author

Final just for interest question ;)

would https://docs.oracle.com/javase/7/docs/api/javax/sql/rowset/serial/SerialArray.html help in this situation in any way?

@vlsi
Copy link
Member

vlsi commented Jan 6, 2017

Ah, rowset indeed could help here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants