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

Implement collection type extensions #161

Open
beikov opened this issue Sep 28, 2015 · 2 comments
Open

Implement collection type extensions #161

beikov opened this issue Sep 28, 2015 · 2 comments

Comments

@beikov
Copy link
Member

beikov commented Sep 28, 2015

In SQL 99 the array type was added which is very convenient especially when indexes are possible. There are various databases that have support for collection types in one or another way. We should take a look into that and try to implement an abstraction for that.

  • PostgreSQL has full native support for array types
  • DB2 has XML support which can be used to emulate arrays. Not very storage space friendly but one can definitely afford the space when already being able to pay for DB2 licenses
  • MSSQL has XML support too
  • Oracle has native support for array types
  • MySQL has XML support too
  • H2 has native support for array types

Regarding JDBC Support

Related issues

Also see: https://github.com/mopano/hibernate-array-type

@beikov beikov self-assigned this Sep 28, 2015
@beikov beikov added this to the 1.2.0 milestone Sep 28, 2015
@beikov beikov removed this from the 1.2.0 milestone Feb 19, 2016
@beikov beikov added this to the 1.5.0 milestone Nov 8, 2016
@jwgmeligmeyling
Copy link
Collaborator

A PR for an array datatypes module for Hibernate has been proposed hibernate/hibernate-orm#1499 . Personally I use the array custom types provided by vladmihalcea/hibernate-types. Both implementations rely on Connection#createArrayOf(String typeName, Object[] elements). Whilst Oracle supports native array types, based on the comments it seems this method is not implemented in their JDBC driver. I am uncertain about H2.

I am also uncertain whether we should emulate array support for databases that do not. It makes this feature drastically more complicated. Not only do we have to emulate the collection storage, but also any of the collection array functions. We'd also lose valuable type information that databases with native array implementations will have.

I actually toyed around with pgjdbc/pgjdbc#381 a little myself. PostgreSQL's array_agg can return a record array, which could benefit from proper struct handling at the driver level. I wanted to use this in combination with array_agg to obtain record arrays and fetch multiple plural non-set associations in this way (while also eliminating redundant data in the cross product). The feature is unfortunately difficult to implement. Primarily because the struct is basically received as a string value from the DB and type info for the struct members would have to be retrieved separately as far as I remember. Given the little interest in the past few years, I doubt whether this will ever be implemented.

@beikov
Copy link
Member Author

beikov commented Sep 15, 2019

The main purpose of emulating this via XML or JSON would be to reduce the amount of data that needs to be fetched when wanting to fetch collections. I don't know if we can make that happen for hibernate native collections, but the potential benefits for entity views are huge.

I would like to use that as default fetch strategy for collections as it should be the most efficient way of fetching nested data. It avoids cross products and also avoids separate queries. We can make use of more efficient pagination as we don't have to handle cardinality/cross product due to collections and generally should be able to implement more efficient collection filtering due to filters being pushed into the collection aggregation.

Array support in postgresql is nice to support because it has some nice filter/index performance benefits to it, so that's something I definitely want to add as a separate feature.
Type information is definitely something we have to be able to retain for arrays, as accessing elements should produce validly typed nodes. For that, I think we need a special array type registry to also be able to produce a valid array type when aggregating individual values.

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

No branches or pull requests

2 participants