I have a JPA entity instance in the web UI layer of my application. I'd like to know at anytime if this entity has been already persisted in database or if it is only present in the user session.
It would be in the business layer, I would use entitymanager.contains(Entity) method, but in my UI layer I think I need an extra attribute indicating whether the entity has been saved or not. How implement that ? I'm considering following option for the moment:
- a JPA attribute with a default value set by the database, but would force a new read after each update ?
- a non JPA attribute manually set in my code or automatically set by JPA?
Any advice / other suggestions ?
I'm using JPA 1 with Hibernate 3.2 implementation and would prefer stick to the standard.