one-to-many 映射
这样查询:
select pk from PoisonKind pk left outer join pk.poisons ps where ps.id='1234'
这样查询:
select pk from PoisonKind pk left outer join pk.poisons ps where ps.id='1234'
解决方案 »
- java命令问题求助
- freemarker模板+hibernate分页问题,各位前辈帮帮忙啊
- 大家讨论下网页的横屏设计 Come on
- 各位高手帮我看一看这是怎么会事?十分感谢!!!
- 数据库怎么就连接不上呢?高分求帮助
- linux下tomcat的问题!
- 字符串问题
- 英文版操作系统下用Jbuilder时不能显示中文,一输入中文就变成方格,怎么办?
- 关于JDBC连接问题 急用!!!!跪求!!!
- JB8+WEBLOGIC7部署CMP时出错,如何解决?
- 我下了FCKEditor for java版的,在Tomcat上安装怎么老是有问题,总是提示找不到包,请帮看看?
- 请教tomcat与jboss的区别。
private String id;
private PoisonKind poisonKind;
}public class PoisonKind {
private String id;
private List poisons;
}
java.lang.RuntimeException: org.hibernate.QueryException: unexpected token: outer [select count(poison) from systemset.poisonKind.poisonKind pk outer join pk.poisons]
unexpected token: outer
应该使用 left outer join 联合查询。
select pk from PoisonKind pk, pk.poisons ps
where
pk.kindId = ps.kindId
ps.poisonId = '1234'
注意这个提示:
unexpected token: outer
应该使用 left outer join 联合查询。”改为left outer join 联合查询
出现下面错误信息:java.lang.ClassCastException///////////////HQL_查找数据库语句为:
String sql = "from systemset.poisonKind.poisonKind pk left outer join pk.poisons";
我用得很好啊?
我的Hsql:
select dept from Department dept left outer join dept.persons us where us.id='1'
Hibernate转换后的Sql:
select department0_.id as id, department0_.Department_Name as Departme2_ from T_Department department0_ left outer join T_Person persons1_ on department0_.id=persons1_.departmentID where (persons1_.id='1' )
String userId="1";
List list=userDao.find("select dept from Department dept left outer join dept.persons us where us.id='1'");
try {
for (Iterator it = list.iterator(); it.hasNext();) {
Department department = (Department) it.next();
System.out.println("departmentName=" + department.getDepartmentName());
}
} catch (Exception e) {
e.printStackTrace();
}
}
select dept from Department dept left outer join dept.persons us
不可以读取所有的名称嘛?!
String sql = "from systemset.poisonKind.poisonKind pk left outer join pk.poisons pkn";
////SQL字符处理,主要是加入查询条件,如果是全部显示,可把这部分代码删除。
if ("search".equals(search))
{
String selectsql;
//<search>
sql += " where ";
sql += " pkn ";
sql += "='";
if ("NULL".equals(expression) || "".equals(expression))
{
sql += m_poisonForm.getPOISONID();
}
else
{
sql += expression;
} sql += "'";
//</search>
} //<分页>
m_poisonDAO.setLength(15);//设置每页显示记录数
int ipage;//当前页
try
{
String page = request.getParameter("page");//分页参数,读取请求的当前页
ipage = java.lang.Integer.parseInt(page, 10);
}
catch (Exception e)
{
ipage = m_poisonForm.getPage();
}
if (ipage < 1)
ipage = 1;
Collection col = m_poisonDAO.findSQL("select pk " + sql,
"select count(pk.poisons) " + sql, ipage);//通过DAO对象查询数据
System.out.print("jjjjklkjkkkj");//能打印出来
request.setAttribute("poison", col); //保存数据 String pagestr = m_poisonDAO.getPagestr(ipage);//分页字符串,分页内容
if (!"search".equals(search))
//查找和全部显示两个不同的操作,其分页字符串不同,在此进行处理。如果是全部显示则去
//掉"search=search&"
{
pagestr = pagestr.replaceAll("search=search&", "");
}
m_poisonForm.setPagestr(pagestr);
m_poisonForm.setAction(action);
request.setAttribute("poisonForm", m_poisonForm);
//</分页> return mapping.findForward("success"); }
<td align="center"><bean:write name='poison' property='KINDNAME' /></td>
<td align="center"><bean:write name='poison' property='NAME' /></td>
<td align="center"><bean:write name='poison' property='ENGLISH' /></td>
<td align="center"><bean:write name='poison' property='POISONCASE' /></td>
<td align="center"><bean:write name='poison' property='SPEC' /></td>