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 queries with array indexes
PostPosted: Wed Jan 30, 2008 8:50 pm 
Newbie

Joined: Wed Jan 30, 2008 8:30 pm
Posts: 1
Hello,

Postgres allows for columns with arrays. I found several posts here and on the internet that show how to insert an array into the database.

However, I found nothing that allowed the creation of this SQL query in HQL

select * from TABLE where COLUMN[1] > 25;

Just to elaborate - that query, in Postgres, will return all rows that have the 1st element in COLUMN > 25.


We're using:
Hibernate 3.
No mapping xmls - purely annotated.
Query causing errors:
Code:

            Query q = session.createQuery("from ASETest a where a.string[1] = 'a'");


This works fine.
Code:

            Query q = session.createQuery("from ASETest ");


I'm assuming the
Code:
[]
mean something special because with them included, the query doesn't even compile, and I see a Class cast exception.

Code:
java.lang.ClassCastException: org.hibernate.type.CustomType
   at org.hibernate.hql.ast.tree.DotNode.resolveIndeDotNode.java:179)
   at org.hibernate.hql.ast.tree.IndexNode.resolve(IndexNode.java:63)
   at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:94)
   at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:90)


Now, it might be that this can't be done with HQL, but does anyone have solutions or workarounds short of using SQL-JDBC?

The closest someone came to the same problem was this:
http://forum.hibernate.org/viewtopic.php?t=946973&highlight=postgres+array

Thanks.


Top
 Profile  
 
 Post subject: Re: Postgres queries with array indexes
PostPosted: Wed Jan 30, 2008 11:27 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
You could use createSQLQuery and pass a valid sql statement instead of HQL. Hibernate is also able to transform the result to your entity.



Farzad-


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.