I'm new to persistence and I want to do the following:
1) Load a part of database into entities and store them in a file
2) Load these entities from file, put them in managed context (so that all the @JoinColumn and @JoinTable, especially those with lazy fetch type, would work normally) and make sure that I don't accidentally update database with them.
The point of all that is that every time I start the application I don't want to call database for the table that almost never change - so I want to store them locally, preferably in a file.
While part 1) was pretty easy, I have some concerns as to part 2). I figured that loadObject and em.persist() would work fine as long as I make sure not to call em.flush().
But at one point I'd like to check if the object in database hasn't been changed. If I call persist() on my de-serialized entity, and at the same time database changed, after flushing which version would remain?
Is there a better way to do this?