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 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
Previous Topic:JPA validation error in Eclipse Neon persistence.xml
Next Topic:EclipseLink + Stream + Java 8
Goto Forum:
  


Current Time: Thu Dec 14 08:19:46 GMT 2017

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

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