hibernate schema 设置
hibernate在实现实体映射时,DB无需强行指定。部署时会较对DB户名和密码,根据用户名以访问的表完成实体映射。如果一个帐号可以访问一个数据库的下多个表,以oracle为例用户user1下面有表table1 ,user2下面也有table1,且user1有user2的所有权限,那么部署时可能就会搞错table,出于安全hiberante在配置时设置默认的schema较为安全。EJB也是同理,建立orm.xml。
<?xml version="1.0" encoding="UTF-8"?><entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/ormhttp://java.sum.com/xml/ns/persistence/orm_1_0.xsd"version="1.0"><persistence-unit-metadata><persistence-unit-defaults><schema>user1</schema></persistence-unit-defaults></persistence-unit-metadata></entity-mappings>
<property name="hibernate.default_schema">user1</property>
<hibernate-mapping> <class name="one.to.many.Person" table="one_to_many_person" catalog="user1"></hibernate-mapping>