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.