-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Postgres inet type operators
PostPosted: Fri Apr 22, 2011 5:31 pm 
Newbie

Joined: Fri Apr 22, 2011 5:13 pm
Posts: 2
I am trying to use Hibernate/JPA to query a table that has a Postgres inet type. If I do simple things like retrieve all of the rows or retrieve a row by the key (which is a long, not an inet) it works fine and Hibernate pulls all of the columns back putting the inet into a String attribute in my entity.

The problem is when I want to query against the inet type and use one of the Postgres operators for inet's, like "<<=". Trying to do a native JPA type query like this:

select sm from SiteMap sm where sm.network <<= inet('192.168/16')

results in this exception:

java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: <= near line 1, column 76 [select sm from gov.pnnl.matrix.cyber.entities.SiteMap sm where sm.network <<= inet('192.168/16')]

Changing it to a native SQL query, like this:

select sm.site_id, sm.site_name, sm.network from site_map sm where sm.network <<= inet('192.168/16')

results in this exception:

javax.persistence.PersistenceException: org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214)

Nothing else changed from the two runs except the query syntax and I called em.createQuery() vs em.createNativeQuery() to generate the Query object. I do have a custom InetType object defined and the annotations on the network attribute in the SiteMap object.

Is there anyway to work with inet types in Hibernate or is this a useless endeavor and I need to find another solution? Searching the forums and google doesn't turn up much and nothing about using the inet operators.

Thanks for any assistance.


Top
 Profile  
 
 Post subject: Re: Postgres inet type operators
PostPosted: Mon Apr 25, 2011 12:30 pm 
Newbie

Joined: Fri Apr 22, 2011 5:13 pm
Posts: 2
I solved my problem by adding a text cast to the inet column in the native query, so now the query looks like this:

select sm.site_id, sm.site_name, text(sm.network) from site_map sm where sm.network <<= inet('192.168/16')

I do have a question why this was necessary? Everything I read says that the Postgres JDBC driver returns the inet type as a String and certainly for my simple queries like findAll and findById I didn't have to do anything special and Hibernate had no problem stuffing those into Strings, why the difference with native queries?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.