使用Hibernate和SQL Server 2008的问题 [英] Problem using Hibernate and SQL Server 2008

查看:126
本文介绍了使用Hibernate和SQL Server 2008的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Hibernate和SQL Server 2008时遇到问题。当我尝试将对象保存到数据库时Hibernate抛出:

I'm having problems using Hibernate and SQL Server 2008. When I try to save an object to database Hibernate throws this:

could not retrieve snapshot: com.my.MyClass

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name `'emanagement.patient_visit'.`

用户在数据库中具有select,insert,update权限。

The user has select, insert,update privileges in database. So I ruled that problem out.

This is the SQL generated:

c> select
patientvis_.account_number,
patientvis_.status as status1_,
patientvis_.cpt_code as cpt3_1_,
patientvis_.locked as locked1_,
patientvis_.state as state1_ ,
patientvis_.userid as userid1_
来自
emanagement.patient_visit patientvis_
其中
patientvis_.account_number =?

select patientvis_.account_number, patientvis_.status as status1_, patientvis_.cpt_code as cpt3_1_, patientvis_.locked as locked1_, patientvis_.state as state1_, patientvis_.userid as userid1_ from emanagement.patient_visit patientvis_ where patientvis_.account_number=?

如果我在SQL Server中运行上面的SQL,它说无效对象名称为emanagement.patient_visit,手动添加dboemanagement.dbo.patient_visit比它会被执行。

If I run the above SQL in SQL Server it says invalid object name emanagement.patient_visit, but if I manually add that "dbo" emanagement.dbo.patient_visit than it will get exsecuted.

那么还有其他任何Hibernate配置吗?

So is there any other Hibernate configuration I need to make?

这是我的Hibernate映射。下面的映射在MySQL下工作。我可以在数据库中读取和更新patient_visit。但是,当切换到MS服务器时,它失败。
我试过其他的hibernate映射工作MySQL和MS服务器,他们都使用相同的声明如下table =db_tableschema =my_database。
唯一的区别是,我在MS Server下创建了这个新的管理数据库,所以我想我错过了MS Server管理工具上的一些特定的数据库配置。
证明这一点的唯一方法是让我把新表从emanagement移动到现有的数据库,看看是否有效。

This is my Hibernate mapping. The below mapping works under MySQL. I can read and update patient_visit in database. But when switching to MS Server it fails. I have tried other hibernate mappings which work for both MySQL and MS Server and they both use the same declarations as below like table="db_table" schema="my_database". The only difference is that I created this new emanagement database under MS Server, so I'm thinking that I missed some specific database configuration on the MS Server management tool. The only way to prove this is for me to move the new tables from emanagement to an existing database and see if it works.

<class name="com.domain.patient.model.PatientVisit" table="patient_visit"    schema="emanagement">
        <id name="accountNumber" type="java.lang.Long">
            <column name="account_number" precision="22" scale="0" />
            <generator class="assigned"/>
        </id> 
        <property name="status" type="string">
            <column name="status"/>
        </property>
        <property name="cptCode" type="string">
            <column name="cpt_code"/>
        </property> 
        <property name="locked" type="boolean">
            <column name="locked" precision="1" scale="0"/>
        </property>  
        <property name="state" type="string">
            <column name="state"/>
        </property>  
        <property name="userId" type="string">
            <column name="userid"/>
        </property>  
               <set name="documents" lazy="false">
            <key column="account_number"/>
            <one-to-many class="com.domain.document.model.Document"/>
        </set>     
    </class>

提前感谢。

推荐答案


那么还有其他的Hibernate配置吗?

So is there any other Hibernate configuration I need to make?

使用当前的设置,我想你必须指定模式。例如,在映射中:

With your current setup, I guess you'll have to specify the schema. For example, in the mapping:

<class name="Users" table="Users" schema="dbo" catalog="suiteaccess">

但是你也可以使用 hibernate.default_schema 属性(请参阅 3.4。可选配置属性)。

为了防止这种情况,您可以创建自己的模式

Just in case, you can create your own schema.

这篇关于使用Hibernate和SQL Server 2008的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆