2

I have two entity managers instances defined in my class, one of which overrides the properties attribute of PersistenceContext, and one which does not:

@PersistenceContext
protected EntityManager em;

@PersistenceContext(properties={@PersistenceProperty(name="hibernate.default_schema", value="archive")})
protected EntityManager emArchive;

I've done this in order to define one entity manager attached to my default schema and the other to be attached to my archive schema.

Here is my persistance.xml:

<persistence-unit name="primary" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:jboss/datasources/PCMain_DS</jta-data-source> 

    <properties>
        <!-- Properties for Hibernate -->
        <!--  property name="hibernate.hbm2ddl.auto" value="update" /-->
        <property name="hibernate.show_sql" value="true" />
    </properties>
</persistence-unit> 

Unfortunately, my program doesn't seem to be working, as when I save an entity with the archive entity manager (emArchive), it gets saved to the default public schema. It seems that the property hibernate.default_schema doesn't get set - but why? How I do switch schema?

My tools/environment:

  • JBoss 7.1
  • EJB
  • JPA
  • Hibernate

All help appreciated, thanks.

4

1 回答 1

0

可以有其他方法来做到这一点,但这里有一种选择:

  1. 在您的 persistence.xml 中定义两个元素
  2. 对于定义的每个持久性单元,使用元素指定每个持久性单元的目标实体名称

这应该照顾在每个持久性单元中持久存在的实体的隔离。

于 2013-02-08T16:17:16.043 回答