openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MiƂosz <mtyle...@o2.pl>
Subject Re: java.lang.IllegalArgumentException: no-named-params
Date Fri, 21 May 2010 14:10:54 GMT
Hi Juraj,

The main problem here is that databases don't like providing table names as parameters. If
you want to use different tables in a query, you have to concatenate strings:

"SELECT id FROM " + tableName + " WHERE (next_run - now() < interval '2 minutes')"

Cheers,
Milosz


> thanks for reply, but your suggested code:
> 
> 
> Rick Curtis wrote:
> > 
> > Query query = em.createNativeQuery("SELECT id FROM :?1 WHERE (next_run -
> > now() < interval '2 minutes')", Long.class);
> > query.setParameter(1, HARVEST_SCHEDULES_TABLE);
> > 
> 
> produces systax error: (i don't know why the exception sais :? and not :?1 ,
> weird)
> 
> 
> 
> >  ERROR: syntax error at or near ":"
> >   Position: 16 {prepstmnt 9497985 SELECT id FROM :? WHERE (next_run -
> > now() < interval '2 minutes') 
> > 
> 
> i tried to change it to this:
> 
> 
> > Query query = em
> > 				.createNativeQuery(
> > 						"SELECT id FROM ?1 WHERE (next_run - now() < interval '2 minutes')",
> > 						Long.class);
> > 
> 
> but its also not working:
> 
> 
> 
> > ERROR: syntax error at or near "$1"
> >   Position: 16 {prepstmnt 8172621 SELECT id FROM ? WHERE (next_run - now()
> > < interval '2 minutes')
> > 
> 
> thanks for some suggestion, Juraj
> 
> -- 
> View this message in context: http://openjpa.208410.n2.nabble.com/java-lang-IllegalArgumentException-no-named-params-tp5080072p5083226.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message