JPA使用同义词而不是表 [英] JPA Entiy on synonym instead of table
问题描述
我有一个基于Seam 2.2的Java EE 5 Web应用程序,其中一些表通过Hibernate 3.3.3映射到JPA 1.0实体。在开发过程中,它运行在Tomcat 6,Oracle 10 XE和Windows 7上。
现在,我们已经请求运营部门将数据模型拆分为一个模式,即所有数据库对象的所有者( myschema
)和一个作为应用程序的数据库用户( myschema_app
)的模式。所以我做了以下工作: - 创建模式
myschema_app
- 根据使用情况(一个或多个
myschema
(常规和n:m中间表) code> select ,insert
,update
,删除
)到myschema_app
- 在
myschema_app $ c中声明私有同义词$ c>为了使用与以前相同的名称并隐藏其他模式的名称前缀
- 将属性
hibernate.default_schema
更改为newpersistence.xml
- 在
context.xml中的Tomcat数据源定义中更改用户名/密码 code>
当我在 hibernate.hbm2ddl.auto $ c时启动应用程序$ c>设置为
validate
,当框架试图创建 EntityManagerFactory
tellin时, g我缺少一张桌子。当我在 myschema_app
连接的sql工具中直接执行select语句时,一切正常。
我明白使用另一个表上的同义词对应用程序是透明的。有没有人有一个想法,我可能忽略了?
我的猜测是hbm2ddl专门为表,而不是为同义词,但是您的应用程序确实应该像表中存在表一样工作。尝试删除hbm2ddl选项并测试您的应用程序。
编辑:看起来我的猜测是真实的: https://forum.hibernate.org/viewtopic.php?p=2438033
I have a Seam 2.2 based Java EE 5 web application with a bunch of tables mapped to JPA 1.0 Entities via Hibernate 3.3.3. During development it's running on a Tomcat 6, Oracle 10 XE and Windows 7.
Now, we had the request by operations department to split the data model into one schema being the owner of all database objects (myschema
) and one schema acting as the application's database user (myschema_app
). So I did the following:
- create schema
myschema_app
- grant object rights on all necessary tables from
myschema
(both regular ones and n:m intermediate tables) and sequences depending on the usage (one or more ofselect
,insert
,update
,delete
) tomyschema_app
- declare private synonyms in
myschema_app
in order to use the same names than before and hiding the other schema's name prefix - change property
hibernate.default_schema
to new schema name inpersistence.xml
- change user/password in Tomcat's datasource definition in
context.xml
When I start the application while having hibernate.hbm2ddl.auto
set to validate
, I get an exception when the framework tries to create the EntityManagerFactory
telling me that a table is missing. When I execute a select statement directly in an sql tool with myschema_app
connected, everything works fine.
I understood that using a synonym going on another table is transparent for the application. Has anyone an idea what I may have overlooked?
My guess is that hbm2ddl seaches specifically for tables, and not for synonyms, but that your application should indeed work as if the tables existed in the schema. Try to remove the hbm2ddl option and test your application.
EDIT: it seems my guess is true: https://forum.hibernate.org/viewtopic.php?p=2438033
这篇关于JPA使用同义词而不是表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!