posted 16 years ago
Hi, I'm new to ORM. I spent a couple days trying to figure it out and I've got some basic stuff working (JPA, annotations, selecting and persisting using native query and jpa query language). Now i want to start designing an approach for my application, so I have some questions related to best practices for JPA.
1. All of my data access is done through DAO objects. I have a baseDAO superclass where in that constructor I create an instance of a protected EntityManager member object and that manager doesn't ever get .close()'d until the finalize() method of my BaseDAO.
Is that ok? Or would it be better to have each method of the DAO call the factory to create/close() a new EntityManager just for the life of the method?
2. Is there a way to detach an Entity from being auto-updated in the database without calling the persist() method? I have a feeling this relates to my manager not being .close()'d until the DAO gets garbage collected...I'd like to be able to change some of my Entity objects database values for display without having the change saved in the db.
3. Let's say I have an Entity with 10 members. I want to do a quick lookup and i'm only going to use 2 of those members for display. What's the best way to tell jpa/hibernate to select and build that entity object with only the data I care about?
Hopefully my questions make sense. if you guys have any links to common JPA practices, that'd be great too.
Thanks,
Aaron