| Excerpts from the test case: @Entity @SelectBeforeUpdate @Audited public class Book implements Serializable { @Id private Long bookId; private String bookName; @ManyToOne @JoinColumn(name = "authorId", updatable = false) // note that the issue dissappears if you delete updatable=false. private Author author; @Version private Long version; ... } public class ORMUnitTestCase extends BaseCoreFunctionalTestCase { public void test() throws Exception { // Test if unnecessary update occurs when using select-before-update for an entity which has immutable many-to-one property. Session s; Transaction t; // ---------------------------------------------------------------------------------------------- // insert s = openSession(); t = s.beginTransaction(); Author author = new Author(1L, "author1"); Book book = new Book(1L, "book1", author); s.save(author); s.save(book); t.commit(); s.close(); // ---------------------------------------------------------------------------------------------- // update s = openSession(); t = s.beginTransaction(); s.update(book); // update unchanged object, but actual update should not happen because Book has SelectBeforeUpdate annotation. t.commit(); s.close(); ... } } After the update of unmodified Book object, there are two revisions for the object. |