本文整理了Java中org.hibernate.query.Query.setParameterList
方法的一些代码示例,展示了Query.setParameterList
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setParameterList
方法的具体详情如下:
包路径:org.hibernate.query.Query
类名称:Query
方法名:setParameterList
[英]Bind multiple values to a named query parameter. This is useful for binding a list of values to an expression such as foo.bar in (:value_list).
[中]将多个值绑定到命名查询参数。这对于将值列表绑定到表达式(如foo)非常有用。输入条(:值_列表)。
代码示例来源:origin: hibernate/hibernate-orm
@SuppressWarnings("unchecked")
private List<DestinationEntity> findDestinationByIds(List<Integer> ids) {
Session session = openSession();
List<DestinationEntity> list = session
.createQuery( "from DestinationEntity de where de.id in (:ids) order by id" )
.setParameterList( "ids", ids ).list();
session.close();
return list;
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testReusingQueryWithNewParameterValues() throws Exception {
try (Session session = openSession()) {
Collection<Long> ids = new ArrayList<>();
Query q = session.createQuery( "select id from Person where id in (:ids) order by id" );
for ( int i = 0; i < 10; i++ ) {
ids.add( Long.valueOf( i ) );
}
q.setParameterList( "ids", ids );
q.list();
ids.clear();
for ( int i = 10; i < 20; i++ ) {
ids.add( Long.valueOf( i ) );
}
// reuse the same query, but set new collection parameter
q.setParameterList( "ids", ids );
List<Long> foundIds = q.list();
assertThat( "Wrong number of results", foundIds.size(), is( ids.size() ) );
assertThat( foundIds, is( ids ) );
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testNamedQuery() {
Session s = openSession();
Transaction t = s.beginTransaction();
s.getNamedQuery("userNameIn")
.setParameterList( "nameList", new Object[] {"1ovthafew", "turin", "xam"} )
.list();
t.commit();
s.close();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testMapKeyExpressionInWhere() {
doInHibernate( this::sessionFactory, s -> {
// JPA form
Query query = s.createQuery( "select te from TestEntity te join te.values v where ?1 in (key(v)) " );
query.setParameter( 1, keyValue );
assertThat( query.list().size(), is( 1 ) );
// Hibernate additional form
query = s.createQuery( "select te from TestEntity te where ?1 in (key(te.values))" );
query.setParameter( 1, keyValue );
assertThat( query.list().size(), is( 1 ) );
// Test key property dereference
query = s.createQuery( "select te from TestEntity te join te.values v where key(v).name in :names" );
query.setParameterList( "names", Arrays.asList( keyValue.name ) );
assertThat( query.list().size(), is( 1 ) );
} );
}
代码示例来源:origin: hibernate/hibernate-orm
params.add( "Public" );
s.createQuery( "from Human where name.last in (?1)" )
.setParameterList( 1, params )
.list();
.setParameterList( 1, params )
.list();
.setParameter( 1, "Yogster" )
.setParameter( 2, "Yogi" )
.setParameterList( 3, params )
.list();
.setParameter( 1, "Yogster" )
.setParameter( 2, "Yogi" )
.setParameterList( 3, params )
.list();
.setParameter( 1, "Yogster" )
.setParameter( 2, "Yogi" )
.setParameterList( 3, params )
.list();
.setParameter( 1, "Yogster" )
.setParameter( 2, "Yogi" )
.setParameterList( 3, params )
.list();
代码示例来源:origin: hibernate/hibernate-orm
@Test
@TestForIssue(jiraKey = "HHH-10577")
public void testMapValueExpressionInWhere() {
doInHibernate( this::sessionFactory, s -> {
// JPA form
try {
Query query = s.createQuery( "select te from TestEntity te join te.values v where ? in (value(v))" );
query.setParameter( 0, new EmbeddableValue( 3 ) );
assertThat( query.list().size(), is( 2 ) );
fail( "HibernateException expected - Could not determine type for EmbeddableValue" );
}
catch ( Exception e ) {
assertTyping( IllegalArgumentException.class, e );
}
// Hibernate additional form
try {
Query query = s.createQuery( "select te from TestEntity te where ? in (value(te.values))" );
query.setParameter( 0, new EmbeddableValue( 3 ) );
assertThat( query.list().size(), is( 2 ) );
fail( "HibernateException expected - Could not determine type for EmbeddableValue" );
}
catch ( Exception e ) {
assertTyping( IllegalArgumentException.class, e );
}
// Test value property dereference
Query query = s.createQuery( "select te from TestEntity te join te.values v where value(v).value in :values" );
query.setParameterList( "values", Arrays.asList( 3 ) );
assertThat( query.list().size(), is( 2 ) );
} );
}
代码示例来源:origin: hibernate/hibernate-orm
.setParameterList( 1, namesArray )
.setParameterList( 2, citiesArray )
.list();
代码示例来源:origin: hibernate/hibernate-orm
.setParameterList( "employeegroupIds", parameters ).list();
代码示例来源:origin: hibernate/hibernate-orm
assertEquals( s.createQuery("from Person p where p.class = Person").list().size(), 1 );
assertEquals( s.createQuery("from Person p where type(p) in :who").setParameter("who", Customer.class).list().size(), 1 );
assertEquals( s.createQuery("from Person p where type(p) in :who").setParameterList("who", new Class[] {Customer.class, Person.class}).list().size(), 2 );
s.clear();
代码示例来源:origin: hibernate/hibernate-orm
assertEquals( s.createQuery("from Person p where p.class = Person").list().size(), 1 );
assertEquals( s.createQuery("from Person p where type(p) in :who").setParameter("who", Customer.class).list().size(), 1 );
assertEquals( s.createQuery("from Person p where type(p) in :who").setParameterList("who", new Class[] {Customer.class, Person.class}).list().size(), 2 );
s.clear();
代码示例来源:origin: hibernate/hibernate-orm
assertEquals( s.createQuery("from Being b where b.class = Alien").list().size(), 1 );
assertEquals( s.createQuery("from Being b where type(b) = :what").setParameter("what", Alien.class).list().size(), 1 );
assertEquals( s.createQuery("from Being b where type(b) in :what").setParameterList("what", new Class[] { Alien.class, Human.class }).list().size(), 2 );
assertEquals( s.createQuery("from Alien").list().size(), 1 );
s.clear();
代码示例来源:origin: hibernate/hibernate-orm
).setParameterList(
"groups",
new Long[] { group1.getId(), group2.getId() }
代码示例来源:origin: sanluan/PublicCMS
public Query<?> getQuery(Session session, String sql) {
Query<?> query = session.createQuery(sql);
if (null != map) {
for (String key : map.keySet()) {
query.setParameter(key, map.get(key));
}
}
if (null != arrayMap) {
for (String key : arrayMap.keySet()) {
query.setParameterList(key, arrayMap.get(key));
}
}
if (null != firstResult) {
query.setFirstResult(firstResult);
}
if (null != maxResults) {
query.setMaxResults(maxResults);
}
if (null != cacheable) {
query.setCacheable(cacheable);
} else {
query.setCacheable(true);
}
return query;
}
代码示例来源:origin: sanluan/PublicCMS
public Query<?> getQuery(Session session, String sql) {
Query<?> query = session.createQuery(sql);
if (null != map) {
for (String key : map.keySet()) {
query.setParameter(key, map.get(key));
}
}
if (null != arrayMap) {
for (String key : arrayMap.keySet()) {
query.setParameterList(key, arrayMap.get(key));
}
}
if (null != firstResult) {
query.setFirstResult(firstResult);
}
if (null != maxResults) {
query.setMaxResults(maxResults);
}
if (null != cacheable) {
query.setCacheable(cacheable);
} else {
query.setCacheable(true);
}
return query;
}
代码示例来源:origin: com.atlassian.hibernate/hibernate.adapter
@Override
public Query setParameterList(final String name, final Collection vals) throws HibernateException {
try {
if (queryV2ForCompare != null) {
queryV2ForCompare.setParameterList(name, vals);
}
query.setParameterList(name, vals);
} catch (final PersistenceException ex) {
throw HibernateExceptionAdapter.adapt(ex);
}
return this;
}
代码示例来源:origin: com.atlassian.hibernate/hibernate.adapter
@Override
public Query setParameterList(final String name, final Object[] vals) throws HibernateException {
try {
if (queryV2ForCompare != null) {
queryV2ForCompare.setParameterList(name, vals);
}
query.setParameterList(name, vals);
} catch (final PersistenceException ex) {
throw HibernateExceptionAdapter.adapt(ex);
}
return this;
}
代码示例来源:origin: com.atlassian.hibernate/hibernate.adapter
@Override
public Query setParameterList(final String name, final Collection vals, final Type type) throws HibernateException {
try {
if (queryV2ForCompare != null) {
queryV2ForCompare.setParameterList(name, vals, type);
}
query.setParameterList(name, vals, TypeV5Adapter.adapt(session.getSessionFactory(), type));
} catch (final PersistenceException ex) {
throw HibernateExceptionAdapter.adapt(ex);
}
return this;
}
代码示例来源:origin: hibernate/hibernate-ogm
@Test
@TestForIssue(jiraKey = "OGM-581")
public void testParameterList() throws Exception {
List<String> paramList = Arrays.asList( "Lama", "Puma" );
List<?> result = session.createQuery( "from Helicopter h where h.name IN (:names)" ).setParameterList( "names", paramList ).list();
assertThat( result ).onProperty( "name" ).containsOnly( "Lama" );
}
代码示例来源:origin: hibernate/hibernate-ogm
@Test
@TestForIssue(jiraKey = "OGM-581")
public void testParameterListWithLongList() throws Exception {
List<Long> paramList = Arrays.asList( 1L, 2L, 4L );
List<?> result = session.createQuery( "from Author a where a.id IN (:ids)" ).setParameterList( "ids", paramList ).list();
assertThat( result ).onProperty( "id" ).containsOnly( 1L, 2L );
}
代码示例来源:origin: hibernate/hibernate-ogm
@Test
@TestForIssue(jiraKey = "OGM-581")
public void testParameterListWithLongArray() throws Exception {
Long[] paramArray = new Long[] { 1L, 2L, 4L };
List<?> result = session.createQuery( "from Author a where a.id IN (:ids)" ).setParameterList( "ids", paramArray ).list();
assertThat( result ).onProperty( "id" ).containsOnly( 1L, 2L );
}
内容来源于网络,如有侵权,请联系作者删除!