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.
|