Bug 550477 - Empty arrays are inserted as NULL values
Summary: Empty arrays are inserted as NULL values
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-27 08:06 EDT by Thorsten Meinl CLA
Modified: 2022-06-09 10:09 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thorsten Meinl CLA 2019-08-27 08:06:19 EDT
When trying to insert an array with zero elements into an array column in the database, a NULL value is written instead. This is wrong since NULL is fundamentally different from an empty array. Moreover it triggers bug #537657. The bug seems to be in 

org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping.writeFromObjectIntoRow(Object, AbstractRecord, AbstractSession, WriteType)

which doesn't handle the case of an empty collection correctly.

Steps to reproduce (with PostgreSQL):

CREATE TABLE foo (
  bar TEXT ARRAY NOT NULL
)

--

@Entity
@Struct(name = "foo")
public class Foo {
  @Column
  @Array(databaseType = "bar")
  List<String> bar = Collections.emptyList();
}

--

EntityManager.persist(new Foo());
Comment 1 Eclipse Webmaster CLA 2022-06-09 10:09:07 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink