HHH-17380 Add test for issue

This commit is contained in:
Christian Beikov 2023-12-19 16:02:23 +01:00
parent 23a809fc3c
commit 7ac11026d4
2 changed files with 87 additions and 0 deletions

View File

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.version">
<class name="NewEntityWithNullVersionTest$UserAttributes" table="user_attributes">
<id name="id" type="java.lang.Long" unsaved-value="0"/>
<version name="version" type="java.lang.Long" access="field"/>
<property name="name"/>
</class>
</hibernate-mapping>

View File

@ -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;
}
}
}