java连接mysql 用hibernate怎么写查询语句
本帖最后由 love_zongming 于 2013-04-30 20:29:34 编辑 以前用的是sqlserver,现在该为mysql,数据库连接上了,但是以前写的查询报错了
——————————————————
select userinfo0_.id as id0_, userinfo0_.company_name as company2_0_, userinfo0_.user_name as user3_0_,
userinfo0_.mobile_number as mobile4_0_ from Demo.dbo.user_info userinfo0_,Demo.dbo.user_info去掉dbo就可以查询出来,请问要如何解决呢?
Java代码
public int queryAll() {
// TODO Auto-generated method stub
String hql="from UserInfo";
List list = getHibernateTemplate().find(hql);
Java代码
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL [select userinfo0_.id as id0_, userinfo0_.company_name as company2_0_, userinfo0_.user_name as user3_0_, userinfo0_.mobile_number as mobile4_0_ from Demo.dbo.user_info userinfo0_]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:629)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:912)
org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:904)
com.seamoon.demo.dao.impl.UserInfoDAOImpl.queryAll(UserInfoDAOImpl.java:181) MySQL Hibernate ssh
[解决办法]
可以到javaBean的配置hbm.xml中去除表的schame="dbo"属性。