Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Saving to array not working
Saving to array not working [message #1741529] Thu, 25 August 2016 16:00 Go to next message
Luiz E. is currently offline Luiz E.Friend
Messages: 100
Registered: September 2010
Senior Member
I'm using Eclipselink 2.6.3 with Postgres and I'm trying to save and List of strings to an `text[]` column in database

This is what've done so far:

	@Array(databaseType="TEXT[]")
	private List<String> members = new ArrayList<>();


annotated my model with
@Struct(name="members")


when I try save it, I get


       	... 92 common frames omitted
Caused by: org.postgresql.util.PSQLException: Unable to find server array type for provided name TEXT[].
       	at org.postgresql.jdbc.PgConnection.createArrayOf(PgConnection.java:1333) ~[postgresql-9.4.1209.jre7.jar:9.4.1209.jre7]


am I still missing something? my database column is `text[]` as well
Re: Saving to array not working [message #1742230 is a reply to message #1741529] Thu, 01 September 2016 03:13 Go to previous messageGo to next message
Clovis Wichoski is currently offline Clovis WichoskiFriend
Messages: 11
Registered: January 2016
Junior Member
After some refined google search, I think you can solve your problem using @Array(databaseType="text[]"), lowercase.

based on this How create a SQL array from a Java List?

Just give a try, and tell us what you got.
Re: Saving to array not working [message #1742460 is a reply to message #1742230] Thu, 01 September 2016 20:01 Go to previous messageGo to next message
Luiz E. is currently offline Luiz E.Friend
Messages: 100
Registered: September 2010
Senior Member
so, this is what I did:

	@Array(databaseType="text[]")
	@Column(columnDefinition="text[]")
	private List<String> members = new ArrayList<>();


and this in the class definition

@Struct(name="members")


even with the column definition in the field, I had to update my database type manually

ALTER TABLE "public"."organizations" ALTER COLUMN "members" SET DATA TYPE text array
 USING array[members]::text[];


and got exactly the same error, but this time in lowercase hahahaha
Re: Saving to array not working [message #1742461 is a reply to message #1742460] Thu, 01 September 2016 20:22 Go to previous messageGo to next message
Luiz E. is currently offline Luiz E.Friend
Messages: 100
Registered: September 2010
Senior Member
OK, I "kinda" got it

First, I changed the data type in the database (since eclipselink still created it as a varchar(255))
then, I changed the annotations to

@Column(columnDefinition="varchar array")
	@Array(databaseType="varchar")
	private List<String> members = new ArrayList<>();


THEN I added the @Struct annotation and worked

So my observations:
1. Eclipselink doesn't generate the schema if @Struct is present (throws the error "[EL Warning]: ddl: 2016-09-01 22:22:29.532--The default table generator currently only supports generating default table schema from a relational project.")
2. I had to do a lot of workaround to make it work (remove @struct annotation, change database type, re-add struct annotation) and this would be IMPOSSIBLE to do in a continuous integration environment.
3. This is clearly a bug
Re: Saving to array not working [message #1804165 is a reply to message #1742461] Tue, 19 March 2019 15:30 Go to previous messageGo to next message
Satya R is currently offline Satya RFriend
Messages: 4
Registered: January 2018
Junior Member
I am testing with EclipseLink 2.7.4 and PostgreSQL JDBC driver 42.2.5 with Spring Boot 2.1.3.

This feature if worked would have been great to avoid lot of boilerplate converter code. However this is not working (atleast for me)

If I declare the entity with

@Array(databaseType = "text[]")
private List<String> plans;

The JDBC driver method createArrayOf in org.postgresql.jdbc.PgConnection complains.

public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
checkClosed();

int oid = getTypeInfo().getPGArrayType(typeName);

if (oid == Oid.UNSPECIFIED) {
throw new PSQLException(
GT.tr("Unable to find server array type for provided name {0}.", typeName),
PSQLState.INVALID_NAME);

}

So I changed to

@Array(databaseType = "text")
private List<String> plans;

However, beyond that when null/empty collection is being set to this, the code in EclipseLink seems to loose type info:

org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping.writeFromObjectIntoRow(...)

line 623:

Object fieldValue = null;
if (!elements.isEmpty()) {
fieldValue = this.getDescriptor().buildFieldValueFromDirectValues(elements, elementDataTypeName, session);
}
row.put(this.getField(), fieldValue);

on db side:

column "plans" is of type text[] but expression is of type text at character 211

If I force in debug session to compute fieldValue, the error isn't coming.

Anyways, these are observations spending couple of hours. Question is, is this working as documented?

Can this be addressed?

Re: Saving to array not working [message #1804171 is a reply to message #1804165] Tue, 19 March 2019 18:03 Go to previous messageGo to next message
Satya R is currently offline Satya RFriend
Messages: 4
Registered: January 2018
Junior Member
I opened a bug : https://bugs.eclipse.org/bugs/show_bug.cgi?id=545557
Re: Saving to array not working [message #1805193 is a reply to message #1804171] Tue, 09 April 2019 16:20 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Have you tried using the @Array(databaseType="varchar") annotation mentioned above? You might still get the null issue as EclipseLink doesn't know NULL is a collection type, and only has the field type to go by ('text' or 'varchar') to pass to the driver for null typing.

What JDBC driver versions are you using, and how do they state to specify the type?

> edit, I didn't notice you posted the JDBC driver version. EclipseLink docs though haven't been updated in quite some time, so this might be due to behaviour changes from when the feature was first added/tested within the driver itself.

[Updated on: Tue, 09 April 2019 16:24]

Report message to a moderator

Previous Topic:Eclipse Auto Save before build?
Next Topic:Why delete operation ignore the tenant discriminator?
Goto Forum:
  


Current Time: Mon Dec 09 10:25:18 GMT 2024

Powered by FUDForum. Page generated in 0.05251 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top