When using @Synchronized in entity class generated lock property is not marked as transient (hence, it requires not needed field in database).
Current fix would be to have custom lock property within the class (marked with @Transient), and use @Synchronized("<custom_lock_name>"), but it would be nice to have something like @Synchronized(onLock_=@Transient).
I can't think of any reason to ever try to serialize the lock. So, I think that always adding the transient modifier (if it is not static) would be the ideal solution.
Also, initially I think that being able to add annotations to the lock is an overkill. On a second thought however, it might be useful to instruct frameworks and other tools to ignore those fields (e.g. Jackson's @JsonIgnore). But, on a third thought, this seems to be such a rare and particular corner-case that it would probably be better to be manually coded instead of relying on lombok for that.
Further, instances of JPA entities are not designed to be thread-safe and should not be shared among multiple threads or multiple EntityManagers. If you are sharing JPA entities between multiple threads and requiring synchronization on them, you are probably doing something wrong, and this have nothing to do with using lombok.
Right, right. Didn't remember that while thinking of simple multitreading safety.
I leave you this issue in case anyone would prefer using onLock_ for other annotations on lock property (like the one you've already mentioned - @JsonIgnore).
We currently generate an Object[] to be able to serialize it. The problem is that otherwise we would also have to generate deserialization code, otherwise you would get a NullPointerExecption.
The workaround is that you provide a field yourself: @Synchronized("lock").
Most helpful comment
Further, instances of JPA entities are not designed to be thread-safe and should not be shared among multiple threads or multiple
EntityManagers. If you are sharing JPA entities between multiple threads and requiring synchronization on them, you are probably doing something wrong, and this have nothing to do with using lombok.