[hibernate-dev] Are arrays of non-basic elements supported?

Steve Ebersole steve at hibernate.org
Thu Jul 27 10:26:59 EDT 2017


I think that is still confusing.  I'd suggest something like:

<quote>
When discussing arrays, it is important to understand the distinction
between SQL array types and Java arrays that are mapped as part of the
application's domain model.

Not all databases implement the SQL-99 ARRAY type and, for this reason,
Hibernate doesn't support native database array types.

Hibernate does support the mapping of arrays in the Java domain model -
conceptually the same as mapping a List.  However, it is important to
realize that it is impossible for Hibernate to offer lazy-loading for
arrays of entities and, for this reason, it is strongly recommended to map
a "collection" of entities using a List rather than an array.
<quote>


On Thu, Jul 27, 2017 at 2:04 AM Vlad Mihalcea <mihalcea.vlad at gmail.com>
wrote:

> I fixed it with the following commit:
>
>
> https://github.com/hibernate/hibernate-orm/commit/871722dc08ec131cd1f5238e1b48df8db2dcc402
>
> Let me know if it's more clear now.
>
> Vlad
>
> On Wed, Jul 26, 2017 at 7:32 PM, Gail Badner <gbadner at redhat.com> wrote:
>
>> OK, I'll make sure Hibernate also treats an empty array element as
>>  equivalent to null as well.
>>
>> Vlad, thanks for correcting the documentation.
>>
>> On Wed, Jul 26, 2017 at 7:38 AM, Vlad Mihalcea <mihalcea.vlad at gmail.com>
>> wrote:
>>
>>> The docs says:
>>>
>>> When it comes to arrays, there is quite a difference between Java arrays
>>> and relational database array types (e.g. VARRAY, ARRAY). First, not all
>>> database systems implement the SQL-99 ARRAY type, and, for this reason,
>>> Hibernate doesn’t support native database array types. Second, Java arrays
>>> are relevant for basic types only since storing multiple embeddables or
>>> entities should always be done using the Java Collection API.
>>>
>>> I guess the "Second, Java arrays ..." part is indeed a little bit
>>> misleading.
>>>
>>> I created the following issue:
>>>
>>> https://hibernate.atlassian.net/browse/HHH-11891
>>>
>>> Is it a problem if I link the docs to my blog post about how to support
>>> arrays of basic types?
>>>
>>>
>>> https://vladmihalcea.com/2017/06/21/how-to-map-java-and-sql-arrays-with-jpa-and-hibernate/
>>>
>>> Thanks,
>>> Vlad
>>>
>>> On Wed, Jul 26, 2017 at 4:04 PM, Steve Ebersole <steve at hibernate.org>
>>> wrote:
>>>
>>>> That doc section is wrong.  Vlad - can you fix that
>>>>
>>>> We do in fact support arrays of all types including embeddables and
>>>> entities.  However, we have always recommended to not use arrays for
>>>> entities as arrays cannot be lazy loaded (not even using bytecode
>>>> enhancement).
>>>>
>>>> On Mon, Jul 24, 2017 at 6:29 PM Gail Badner <gbadner at redhat.com> wrote:
>>>>
>>>> > Documentation makes it sound like only arrays of basic types are
>>>> supported.
>>>> > [1]
>>>> >
>>>> > I see a test using an array of entities, but I don't see one for an
>>>> array
>>>> > of embeddables. [2]
>>>> >
>>>> > Regards,
>>>> > Gail
>>>> >
>>>> > [1]
>>>> >
>>>> >
>>>> http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#collections-array
>>>> > [2]
>>>> >
>>>> >
>>>> https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/test/java/org/hibernate/test/annotations/array/Contest.java#L40-L42
>>>> > _______________________________________________
>>>> > hibernate-dev mailing list
>>>> > hibernate-dev at lists.jboss.org
>>>> > https://lists.jboss.org/mailman/listinfo/hibernate-dev
>>>> >
>>>> _______________________________________________
>>>> hibernate-dev mailing list
>>>> hibernate-dev at lists.jboss.org
>>>> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>>>>
>>>
>>>
>>
>


More information about the hibernate-dev mailing list