Hibernate Console: how to use List Parameters

已回答

Hi,

 

Im trying to test a query in the Hibernate Console like this one:

 

SELECT u FROM User u WHERE u.id IN :ids

 

Where u.id is a Long field.

How do i need to set the parameter to make it work?

I tried:

  • 1L,2L
  • {1L, 2L}
  • (1L, 2L)
  • Arrays.asList(1L, 2L)

But i didn't manage to work.

Please help!!

Thanks in advance!!

 

0

Try to write parameter list in brackets. According to documentation following syntax is supported:

in and between can be used as follows:

from DomesticCat cat where cat.name between 'A' and 'B'
from DomesticCat cat where cat.name in ( 'Foo', 'Bar', 'Baz' )
0

Hi Andrey, 

Thanks for your response, but i meant how to deal with parameters list in the IntelliJ "Hibernate Console", not in JPQL. Maybe it'll be clear with the following image:

- screenshot (i don't know why i couldn't upload this image in the comment)

Thanks in advance.

0

Sorry it is not quite clear: on the screenshot I do not see the complete query you are using. Do you mean how to set parameter list via one parameter when using  dialog? Doesn't it work if use separate user parameter per each list parameter?

0

Yes, i meant how to set a parameter list value when using the dialog.

An example of the query could be:

from DomesticCat cat where cat.name in :catName

That raises a Dialog where you need to set the catName value.

0

So, doesn't it work with 

from DomesticCat cat where cat.name in (:catName, :docName, :anotherName)

 syntax?

0

Yes, that syntax works, is not what I expected, but I'll use it.

Thanks.

0

Just had the case, the "(1L, 2L)" syntax worked for me right now (IDEA version 2021.1.3).

0

请先登录再写评论。