3

I am using Hibernate Configuration in my persistence.xml. I want two persistence units. One for persisting or editing to the db. And the second persistence unit` will only have read access to db.

Database-readonly will be able to perform Only Read Operation to database.

<persistence-unit name="Database-readonly">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
        <validation-mode>CALLBACK</validation-mode>
        <properties>
        .........
        .........
       <properties>

Database-Persist will be able to perform editing to database (persist, modify or delete)

<persistence-unit name="Database-Persist">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
        <validation-mode>CALLBACK</validation-mode>
        <properties>
        .........
        .........
       <properties>

Is there any property in Hibernate configuration that will enable me to implement this ??.

I want to implement this because at the time of reading no transactional lock will be enabled to the database, which means multiple reading can be enabled to the EntityManager.

Question :- Is there any property in Hibernate configuration that will enable me to implement this ??.

Vikrant Kashyap
  • 6,398
  • 3
  • 32
  • 52
  • Any reason of choosing persistence.xml ? `@Transactional(readOnly=true)` can solve to read the data with Hibernate `flushMode=NEVER`. – Vinay Veluri Mar 02 '16 at 12:06
  • I am using Java persistent API with hibernate configuration so, I want read only setting in hibernate configuration such that I can use individual persistence unit as per need. – Vikrant Kashyap Mar 02 '16 at 14:25

0 Answers0