I am trying to persist one of my JPA/EclipseLink models, one attribute location
of type org.postgresql.geometric.PGpoint
is not inserting correctly.
My model looks something like this:
@Entity
@NamedQuery(name="Entity.findAll", query="SELECT * FROM Entity e")
public class Entity {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name="name")
private String name;
@Column(name="location")
private PGpoint location;
@Column(name="date")
private Timestamp date;
@Column(name="user_id")
private Integer user_id;
/* getters and setters */
I am getting this exception:
Internal Exception: org.postgresql.util.PSQLException:
ERROR: column "location" is of type point but expression is of type bytea
I have enabled query logging and determined that the problem seems to be caused by malformed SQL. All attributes following location
seem to be grouped together into a bytea
array. Specifically, JPA is trying to execute an insert like this:
INSERT INTO ENTITY (name, location, date, user_id)
VALUES ("my_name", [B26bf8d677, "2017-05-12 12:33:00.0", 1])
That is, it seems to be trying to insert the last three attributes all into the location
column.
I've also tried storing location
as type String
, which works on one of my other models that only reads location values from the database and never inserts them. That seems to fix the malformed SQL issue since the inserts look like this:
INSERT INTO ENTITY (name, location, date, user_id)
VALUES("my_name", "POINT(42,24)", "2017-05-12 12:33:00.0", 1)
However, it doesn't actually work since I get this exception:
Internal Exception: org.postgresql.util.PSQLException:
ERROR: column "location" is of type point but expression is of type character varying
How can I get the location
attribute to insert correctly?