龙西庄庄主 2013-04-30 20:09 采纳率: 0%
浏览 177
已采纳

java连接mysql 用hibernate怎么写查询语句

以前用的是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就可以查询出来,请问要如何解决呢?
[code="java"]
public int queryAll() {
// TODO Auto-generated method stub
String hql="from UserInfo";
List list = getHibernateTemplate().find(hql);
[/code]
[code="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)

[/code]

  • 写回答

2条回答

  • jinnianshilongnian 2013-04-30 20:40
    关注

    from Demo.dbo.user_info userinfo0_]

    1、检查hibernate配置
    hibernate.default_schema 在生成的SQL中, 将给定的schema/tablespace附加于非全限定名的表名上.
    取值 SCHEMA_NAME

    hibernate.default_catalog 在生成的SQL中, 将给定的catalog附加于非全限定名的表名上.
    取值 CATALOG_NAME

    删掉这两个

    2、看下你的hbm配置文件 是是否有catalog 和 schema 删掉

    hibernate sheme和catalog的问题?5
    schema="schemaName" (1)
    catalog="catalogName" (2)


    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器