【问题标题】:Using Hibernate with SQL Server 2008在 SQL Server 2008 中使用休眠
【发布时间】:2012-04-10 14:58:51
【问题描述】:

我在应用程序的数据访问层使用带有 Hibernate 3.0 的 SQL Server 2008。问题是我无法从数据库中读取。 这是我的休眠配置;

<property name="connection.driver_class"> com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="connection.url">jdbc:sqlserver://localhost;databaseName=test;integratedSecurity=true;</property>
<property name="connection.username">not required</property>
<property name="connection.password"></property>
<property name="dialect">org.hibernate.dialect.SQLServer2008Dialect</property    
<property name="hibernate.hbm2ddl.auto">update</property>    
<mapping resource="user.hbm.xml"/>

这里是user.hbm.xml

<class name="ammar.User" table="user" schema="dbo" catalog="test">
    <id name="userId" type="int" column="userId" >
        <generator class="assigned"/>
    </id>

    <property name="userName">
        <column name="userName" />
    </property>
</class>

这是我用来从数据库中获取数据的代码。

    SessionFactory sF = new Configuration().configure().buildSessionFactory();
    Session session = sF.openSession();

    User user = (User) session.get(User.class, 1);

    if(user!=null)
        System.out.println(user.getUserName());
    else
        System.out.println("Not Found");

SQLGrammarException 以及 SQLServerException 在我运行时发生。 需要紧急回复。

【问题讨论】:

  • 您在数据库中是否有 id 1 的条目?同时打印堆栈跟踪。
  • 已解决。实际上,“用户”a 是 SQL Server 2008 中的保留字。无论如何,感谢@ManuPK。

标签: sql-server-2008 hibernate jakarta-ee dao


【解决方案1】:

解决了。实际上,“用户”a 是 SQL Server 2008 中的保留字。无论如何,感谢@ManuPK。

【讨论】:

    猜你喜欢
    • 2019-03-06
    • 2014-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-28
    • 2012-03-26
    • 2020-04-05
    • 2010-12-08
    相关资源
    最近更新 更多