DATAJPA-561 - JpaMetamodelEntityInformation now treats primitive version properties correctly.

Previously, we only checked the version attribute's value against null, which effectively invalidly reported a new entity being non-new in case it used primitive types for the version attribute (as it has a default value then).

We now explicitly check for primitive version property types and consider default values to indicate new state.
This commit is contained in:
Oliver Gierke
2014-06-26 16:15:03 +02:00
parent 1ac89e77fa
commit af45da40c6
4 changed files with 34 additions and 1 deletions

View File

@@ -0,0 +1,12 @@
package org.springframework.data.jpa.domain.sample;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Version;
@Entity
public class PrimitiveVersionProperty {
@Id Long id;
@Version long version;
}

View File

@@ -36,6 +36,7 @@ import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.jpa.domain.AbstractPersistable;
import org.springframework.data.jpa.domain.sample.PrimitiveVersionProperty;
import org.springframework.data.jpa.domain.sample.Role;
import org.springframework.data.jpa.domain.sample.SampleWithIdClass;
import org.springframework.data.jpa.domain.sample.SampleWithIdClassPK;
@@ -169,6 +170,18 @@ public class JpaMetamodelEntityInformationIntegrationTests {
assertThat(info.getEntityName(), is("ROLE"));
}
/**
* @see DATAJPA-561
*/
@Test
public void considersEntityWithPrimitiveVersionPropertySetToDefaultNew() {
EntityInformation<PrimitiveVersionProperty, Serializable> information = new JpaMetamodelEntityInformation<PrimitiveVersionProperty, Serializable>(
PrimitiveVersionProperty.class, em.getMetamodel());
assertThat(information.isNew(new PrimitiveVersionProperty()), is(true));
}
protected String getMetadadataPersitenceUnitName() {
return "metadata";
}