---
title: "Hibernate in 出现的问题"
author: "wangyu"
date: "2010-02-07T09:04:20Z"
tags: []
categories: ["企业架构"]
slug: "hibernate-in"
draft: false
lastmod: "2010-02-07T09:04:20Z"
id: 589118
url: "https://wangyu.iteye.com/blog/589118"
---

今天项目中遇到hibernate in查询结果集为空的问题.

```java
	String searchModules = "select m from Module m where m.id in (?)";

		return find(searchModules, temp.keySet());
```

temp是个map
这段执行后抛出异常.
修改后

```java

Object [] objects = temp.keySet().toArray();
		StringBuffer ids = new StringBuffer();
		for (Object object : objects) {
			ids.append("'").append(object).append("'").append(',');
		}
		ids.deleteCharAt(ids.length() - 1);
		String searchModules = "select m from Module m where m.id in ("+ids.toString()+")";
		return find(searchModules);

```