0

I am using Spring boot with JPA. I have two questions

  1. I have two entities Order and OrderLineItems. I am saving the Order entity using orderDao.save(), Which saves line items as well. When I update line-items, only the line-items version is getting updated. I want to update the version of the parent. I don't have OrderLineItemsDao.

  2. All our Entities extend BaseEntity. It has the lastModifiedAt column which is annotated with @UpdateTimestamp which is making all the records dirty. I am planning to remove it, is it fine and update it manually? Or do we have any other way to stop the unnecessary updates to DB?

1
  • #1 isn't a question. Did you mean to ask how you update the version in Order when only a child/OrderLineItem changes? This isn't part of JPA but some providers have solutions (see stackoverflow.com/a/13724804/496099 ) or manual options (stackoverflow.com/questions/2895460/… ). For #2 - why not? I am not familiar with @UpdateTimestamp or when it executes, but maybe try JPA's preUpdate event, which are required to only be called when there are changes (it is dirty). Commented Jul 28, 2022 at 19:44

1 Answer 1

0

I would suggest you use the explicit approach that Chris mentioned, which is to force incrementing the optimistic lock version of that Order entity.

entityManager.lock(parent, LockModeType.OPTIMISTIC_FORCE_INCREMENT); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.