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

Usage of @Array annotation for an array columns requires to annotate Entity class with @Struct annotation and giving a random name #2208

Open
saschacogmob opened this issue Jul 11, 2024 · 0 comments

Comments

@saschacogmob
Copy link

Describe the bug

As described here: https://eclipse.dev/eclipselink/documentation/2.4/jpa/extensions/a_array.htm
you can use the @array annotation on a array column but only in combination with adding the @struct annotation on the class level. One thing is that this feels a bit odd, since it is a normal DB table rather than a Struct type.
But what bothers me a bit more is the fact that the @struct annoation has a mandatory property name.
And it seems I can give an arbitrary value for it and it works.
But can this be intended?
I think it can be confusing and therefore I think it is a bug.

To Reproduce

Here an Example:

DB Table with Array column:

CREATE TABLE my_table (
	id bigserial NOT NULL,
	job_title varchar NULL,
	list_of_names varchar(50) ARRAY[5] NULL
);

Corresponding java JPA class:



	import javax.persistence.Entity;
	import javax.persistence.Table;
	import javax.persistence.Column;
	import org.eclipse.persistence.annotations.Array;
	import org.eclipse.persistence.annotations.Struct;
	import java.util.List;

	@Entity
	@Table(name = "my_table")
	@Struct(name = "SomeRandomValue") // prerequisite for using the @Array annotation on listOfNames ([EclipseLink-157] error otherwise)
	public class MyEntity {
		
		@Column(name = "id", unique = true, nullable = false)
		private String id;
		
		@Column(name = "job_title")
		private String job_title;

		@Array(databaseType = "VARCHAR")
		@Column(name = "list_of_names")
		private List<String> listOfNames;
	}

What the above demnonstrates that the Struct annotation requires a mandatory name and one can give a random value. In this case "SomeRandomValue".
Without the @struct annotation it fails during runtime with "[EclipseLink-157] " error

Expected behavior
I think the @struct annotation shouldn't be required at all.
But if it required there should be some common understanding what a suitable value for the name attribute is.

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

No branches or pull requests

1 participant