0

I am of the current understanding as I learn about EJB's in school:

Statement 1

In CMP (Container-managed persistence), the container will tell the database synchronize row in database when different entity beans try too access the same row at the same time.

Statement 2

As far as I know though, every database has a background mechanism that auto synchronizes every row when there are multi accesses to it. So, when developers program against a database, they don't care about underlying synchronous access to rows.

So, my question is - if statement 2 is true, why does an EJB container need to synchronize entity bean access to database rows? If my thinking is wrong, please correct me.

4

1 回答 1

1

If I understood your question correctly, you're asking about locking.

By default JPA provides optimistic locking controlled with the @Version annotation.

You should check for OptimisticLockExceptions.

Other locking modes are possible:

http://docs.oracle.com/javaee/6/tutorial/doc/gkjhz.html

http://docs.oracle.com/javaee/6/tutorial/doc/gkjiu.html

于 2012-05-01T11:25:06.057 回答