Can't insert PGpoint type with JPA

旧街凉风 提交于 2019-12-07 15:50:27

问题


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?

来源:https://stackoverflow.com/questions/43947713/cant-insert-pgpoint-type-with-jpa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!