简体   繁体   中英

EJB : does container need to synchronize entity bean persist?

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.

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 OptimisticLockException s.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM