The question I'm asking is pretty simple but seemingly impossible to find an answer to. I'm using Spring Data JPA and I have a JDBC/JPA DataSource
(which is PostgreSQL, but that shouldn't matter), which is preloaded with data and I simply am trying to read from it.
How do I construct my POJO so that I can have a List<String>
field that doesn't require an extra join table? Here is an example entity class I have:
@Entity
@Table(name = "pojo", schema = "pojoschema")
public class POJO {
@Id
@Column(name = "id", columnDefinition = "uuid")
private String id;
@Column(name = "a_string", columnDefinition = "text")
private String aString;
@Column(name = "strings", columnDefinition = "text[]")
@ElementCollection
private List<String> strings;
// getters/setters
}
Doing this I get a org.postgresql.util.PSQLException: ERROR: relation "pojo_strings" does not exist
.
Why does hibernate think that the String
s I want are in another table? How do I fix this behavior? I'm simply trying to map a PostgreSQL text[]
column back to a List<String>
in a POJO via JPA.