Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Postgres inet type
Postgres inet type [message #980721] Sun, 11 November 2012 18:05 Go to next message
Eclipse UserFriend
So, using eclipselink and inet type is nicely cast to string when reading.

But on insert something is wrong:

Caused by: org.postgresql.util.PSQLException: ERROR: column "..." is of type inet but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.


So I must override using descriptor customizer? Is kinda strange since I can insert into that column the IP as normal string.

This gets generated, nothing special (And it dies):
Call: INSERT INTO "table" (columns ...) VALUES (?, ?, ?, ?, ?, ?, ?)
	bind => [7 parameters bound]


And this WORKS:
INSERT INTO "table" (columns ...)
VALUES (... '127.0.0.1' ...);


So when I call an ordinary query I can pass inet field as standard string and it all works. When a prepared statement it called via eclipselink and inet is bound as a string everything dies. A bug certiainly, but is there any workaround or a trick to make it work? Converter doesn't seem to work.
Re: Postgres inet type [message #981629 is a reply to message #980721] Mon, 12 November 2012 10:18 Go to previous messageGo to next message
Eclipse UserFriend
If it accepts your string inline with the statement, you might try turning parameter binding off.
See
http://eclipse.org/eclipselink/documentation/2.4/jpa/extensions/q_bindparameters.htm
for info on the property

[Updated on: Mon, 12 November 2012 11:11] by Moderator

Re: Postgres inet type [message #982992 is a reply to message #981629] Tue, 13 November 2012 10:37 Go to previous messageGo to next message
Eclipse UserFriend
What database type is inet? If you JDBC driver does not allow binding a String, then you can use a Converter to convert to the required database type.
Re: Postgres inet type [message #984694 is a reply to message #980721] Wed, 14 November 2012 17:37 Go to previous messageGo to next message
Eclipse UserFriend

Well I can always use a native query and I will for now.

@Chris: Yes it accepts param inet as inline string in a native query. The link you posted doesn't make it exactly clear (I am using java EE!) if I can just use @QueryHint annotation on a @Entity class to override the behaviour just for it? That would be perfect I guess. Does it do escaping if you do it like that automatically?

@James: The problem is I don't know. Manual doesn't say: http://www.postgresql.org/docs/9.2/static/datatype-net-types.html And yea, I am quite sure that is the problem. Strangely though it accepts string inline no problems. I guess I need to take this to postgre people.

[Updated on: Wed, 14 November 2012 17:44] by Moderator

Re: Postgres inet type [message #985579 is a reply to message #984694] Thu, 15 November 2012 09:04 Go to previous messageGo to next message
Eclipse UserFriend
You might find this link helpful:
https: github.com/ancoron/pg-inet-maven/wiki/Support-custom-data-types-in-EclipseLink
Re: Postgres inet type [message #985698 is a reply to message #980721] Thu, 15 November 2012 12:40 Go to previous messageGo to next message
Eclipse UserFriend
You need to add parameter ?stringtype=unspecified to your JDBC connection string. This is due to reason that inets in your query are explicitly casted to Strings by PostgreSQL JDBC driver.
Re: Postgres inet type [message #985744 is a reply to message #985698] Thu, 15 November 2012 17:14 Go to previous message
Eclipse UserFriend
Query hints apply only to the query they are added to, while if the propertiy is set in the persistence.xml it will apply to every query. So the @QueryHint neededs to be added within a named query annotation, not an entity. Example 4-27 needs improvement but I don't have an example handy at the moment, I'll try fixing the example tomorrow.
Previous Topic:Pagination - FIRST_ROWS_N
Next Topic:PostGIS + Eclipselink
Goto Forum:
  


Current Time: Wed Jul 23 19:44:05 EDT 2025

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

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

Back to the top