Search code examples
javajpaejbejb-3.0

What is the EJB 2 ReadOnlyBean equivalent in JPA.EJB3?


I'm migrating a EJB 2.1 project to JPA/EJB3. There are lot of EJB ReadOnlyBeans that I want to get rid off.

Does JPA/EJB3 designed to support ReadOnlyAccess intrinsically, in such a way that ReadOnlyBeans are not required?

EJB 2: I have the Isolation level set at READ_COMITTED using JBOSS in MSSQLSERVER. When Txn x, tries to reads a row that is locked by txn Y, it will wait untill txn Y commits the changes to that row. For scenarios where we dont need the latest data, we use ReadOnlyBeans to fetch the data without any transaction.

JPA/EJB3: I still have the isolation level set at READ_COMITTED. If I remove the ReadOnlyBeans, would there be any problem?

Since TransactionSceoped Entity managers use different instance of Entities, there should not be any problem in removing the ROBeans, is that correct?

Thank you!


Solution

  • If I understand correctly, you're asking how to make a JPA entity immutable. If so, you can either

    • mark all of its properties as insertable = false, updatable = false (using @Column, @JoinColumn etc.)
    • use a vendor-specific extension (e.g. @Immutable in Hibernate, @ReadOnly in EclipseLink etc.)

    That being said, I don't think the use case you describe needs entities to be read-only. If you're reading the entities without any transaction, they become detached immediately after being loaded, so there is no risk of accidentally modifying them (unless you specifically opted-in for an extended persistence context).