-->
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.  [ 4 posts ] 
Author Message
 Post subject: how to cancel where clause effect?
PostPosted: Mon Jun 04, 2007 10:54 pm 
Newbie

Joined: Mon Jun 04, 2007 10:39 pm
Posts: 3
hi all
in JPAQL
i wanna cancel the where clause effect in order to use the following example query
select u from user u where u.name= :name
the question is what to put for the value of the parameter:name to make the query get all the objects ,ie. make it match against any name,i know that this can be achieved with omiting the where clause alltogether but my real world query is much complex and i cannot guarentee that each time i run the query all the parameters will be assigned so i want to neutralize the effect of effect of the unassigned parameters by making a default that get all objects, i cannot use dynamically generated sql or jpaql as my db perform much much better with precompiled queries
please help me and tell me if ur solution is portable among JPA providers(in the spec )or just available in hibernate
thanx alot


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 05, 2007 1:39 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
You could design your query to do this :-

e.g.

select u from user u where u.age= :age

If you want to use -1 as default for age then modify the query to:

select u from user u where (u.age= :age or -1 = :age)

This would "neutralize the effect".


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 05, 2007 9:30 am 
Newbie

Joined: Mon Jun 04, 2007 10:39 pm
Posts: 3
this may work for primitives but for compound objects ,i cannot figure how to do it


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 05, 2007 9:53 am 
Newbie

Joined: Mon Jun 04, 2007 10:39 pm
Posts: 3
hi again
after some thiking ,i found ur solution seems to be reasonable but when i used it i got classCastException
Exception in thread "main" java.lang.ClassCastException: java.lang.Integer
at org.hibernate.type.StringType.toString(StringType.java:44)
at org.hibernate.type.NullableType.toLoggableString(NullableType.java:218)
at org.hibernate.pretty.Printer.toString(Printer.java:76)
at org.hibernate.engine.QueryParameters.traceParameters(QueryParameters.java:277)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:151)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
at com.corp.jpa.test.TestUserPersist.main(TestUserPersist.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.