diff --git a/hibernate-core/src/test/java/org/hibernate/test/version/NewEntityWithNullVersion.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/version/NewEntityWithNullVersion.hbm.xml new file mode 100644 index 0000000000..1877d9c74b --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/version/NewEntityWithNullVersion.hbm.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + diff --git a/hibernate-core/src/test/java/org/hibernate/test/version/NewEntityWithNullVersionTest.java b/hibernate-core/src/test/java/org/hibernate/test/version/NewEntityWithNullVersionTest.java new file mode 100644 index 0000000000..677e869620 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/version/NewEntityWithNullVersionTest.java @@ -0,0 +1,68 @@ +package org.hibernate.test.version; + +import java.io.Serializable; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; + + +@TestForIssue(jiraKey = "HHH-17380") +public class NewEntityWithNullVersionTest extends BaseCoreFunctionalTestCase { + + @Override + protected String[] getMappings() { + return new String[] { "NewEntityWithNullVersion.hbm.xml" }; + } + + @Override + protected String getBaseForMappings() { + return super.getBaseForMappings() + "version/"; + } + + @Test + public void testMergeDetachedEntityWithIdentityId() { + UserAttributes item = new UserAttributes(); + item.id = 123L; + item.name = "Abc"; + inTransaction( + session -> { + session.saveOrUpdate( item ); + } + ); + } + + public static class UserAttributes implements Serializable { + + private Long id = 0L; + + private Long version; + + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getVersion() { + return version; + } + + public void setVersion(Long version) { + this.version = version; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } +} +