Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Postgres inet type
Postgres inet type [message #980721] Sun, 11 November 2012 18:05 Go to next message
Neikius Mising name is currently offline Neikius Mising name
Messages: 43
Registered: April 2011
Member
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
Chris Delahunt is currently offline Chris Delahunt
Messages: 995
Registered: July 2009
Senior Member
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]

Report message to a 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
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

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.


James : Wiki : Book : Blog : Twitter
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
Neikius Mising name is currently offline Neikius Mising name
Messages: 43
Registered: April 2011
Member

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]

Report message to a 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
Avner Levy is currently offline Avner Levy
Messages: 2
Registered: November 2012
Junior Member
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
Rade  artinovi? is currently offline Rade artinovi?
Messages: 1
Registered: July 2009
Junior Member
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
Chris Delahunt is currently offline Chris Delahunt
Messages: 995
Registered: July 2009
Senior Member
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: Fri Apr 18 04:14:34 EDT 2014

Powered by FUDForum. Page generated in 0.02134 seconds