Mar*_*nio 5 java database sql-server hibernate
我在使用 Hibernate 和 SQL Server 2008 时遇到问题。当我尝试将对象保存到数据库时,Hibernate 会抛出以下错误:
could not retrieve snapshot: com.my.MyClass
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name `'emanagement.patient_visit'.`
Run Code Online (Sandbox Code Playgroud)
用户拥有数据库的选择、插入、更新权限。所以我排除了这个问题。
这是生成的 SQL:
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=?
Run Code Online (Sandbox Code Playgroud)
如果我在 SQL Server 中运行上述 SQL,它会显示无效的对象名称 emanagement.patent_visit,但如果我手动添加“dbo”emanagement.dbo.patent_visit,它将被执行。
那么我还需要进行其他 Hibernate 配置吗?
这是我的 Hibernate 映射。下面的映射在 MySQL 下工作。我可以读取并更新数据库中的病人访问。但当切换到 MS Server 时,它失败了。我尝试过其他适用于 MySQL 和 MS Server 的休眠映射,它们都使用与下面相同的声明,如 table="db_table" schema="my_database"。唯一的区别是我在 MS Server 下创建了这个新的电子管理数据库,所以我认为我错过了 MS Server 管理工具上的一些特定数据库配置。证明这一点的唯一方法是将新表从电子管理移动到现有数据库,看看它是否有效。
<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>
Run Code Online (Sandbox Code Playgroud)
提前致谢。
那么我还需要进行其他 Hibernate 配置吗?
根据您当前的设置,我想您必须指定架构。例如,在映射中:
<class name="Users" table="Users" schema="dbo" catalog="suiteaccess">
Run Code Online (Sandbox Code Playgroud)
但您也可以使用属性指定默认架构hibernate.default_schema(请参阅3.4. 可选配置属性)。
为了以防万一,您可以创建自己的架构。
| 归档时间: |
|
| 查看次数: |
13928 次 |
| 最近记录: |