i've been trying implement pessimistic locking in springboot app. questions are:
- do need add persistence.xml or possible add in pom.xml, if yes how?
- if need add persistence.xml how should like? have tried approach , keep getting error: "this configuration disallows runtime optimization, following listed types not enhanced @ build time or @ class load time javaagent:.... "
i have implemented optimistic locking before , have added @version , couple of more lines. why pessimistic locking complicated? doing wrong?
these dependencies
<dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-data-jpa</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-mail</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> <dependency> <groupid>com.h2database</groupid> <artifactid>h2</artifactid> <scope>runtime</scope> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-test</artifactid> <scope>test</scope> </dependency> <dependency> <groupid>io.jsonwebtoken</groupid> <artifactid>jjwt</artifactid> <version>0.6.0</version> </dependency> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <scope>runtime</scope> </dependency> <dependency> <groupid>org.postgresql</groupid> <artifactid>postgresql</artifactid> </dependency> <dependency> <groupid>javax.persistence</groupid> <artifactid>persistence-api</artifactid> <version>1.0</version> </dependency> </dependencies>
and service
@autowired entitymanager em; @transactional public reservation createreservation(reservationdto reservationdto) { ........ ........ (string id : ids) { table table = em.find(table.class, long.parselong(id)); em.lock(table, lockmodetype.pessimistic_write); em.refresh(table); tablerepository.save(table); .........
and controller
....... try { reservation reservation = reservationservice.createreservation(reservationdto); if (reservation == null){ return new responseentity(httpstatus.bad_request); } emailservice.sendmailinvite(reservation, guest); return new responseentity(httpstatus.ok); }catch (pessimisticlockexception e){ return new responseentity(httpstatus.bad_request); } .......
thank you!
Comments
Post a Comment