diff --git a/src/test/java/org/springframework/data/jpa/domain/sample/SampleWithPrimitiveId.java b/src/test/java/org/springframework/data/jpa/domain/sample/SampleWithPrimitiveId.java new file mode 100644 index 000000000..b7f7b5aa8 --- /dev/null +++ b/src/test/java/org/springframework/data/jpa/domain/sample/SampleWithPrimitiveId.java @@ -0,0 +1,35 @@ +/* + * Copyright 2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.jpa.domain.sample; + +import javax.persistence.Entity; +import javax.persistence.Id; + +/** + * @author Oliver Gierke + */ +@Entity +public class SampleWithPrimitiveId { + + @Id long id; + + /** + * @param id the id to set + */ + public void setId(long id) { + this.id = id; + } +} diff --git a/src/test/java/org/springframework/data/jpa/repository/support/EclipseLinkJpaMetamodelEntityInformationIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/support/EclipseLinkJpaMetamodelEntityInformationIntegrationTests.java index 04e7df3a7..3c6d27ad5 100644 --- a/src/test/java/org/springframework/data/jpa/repository/support/EclipseLinkJpaMetamodelEntityInformationIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/support/EclipseLinkJpaMetamodelEntityInformationIntegrationTests.java @@ -49,6 +49,13 @@ public class EclipseLinkJpaMetamodelEntityInformationIntegrationTests extends @Ignore public void findsIdClassOnMappedSuperclass() {} + /** + * Ignored due to https://bugs.eclipse.org/bugs/show_bug.cgi?id=415027 + */ + @Override + @Ignore + public void detectsNewStateForEntityWithPrimitiveId() {} + @Override protected String getMetadadataPersitenceUnitName() { return "metadata_el"; diff --git a/src/test/java/org/springframework/data/jpa/repository/support/JpaMetamodelEntityInformationIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/support/JpaMetamodelEntityInformationIntegrationTests.java index ed9bc501a..3eb89536c 100644 --- a/src/test/java/org/springframework/data/jpa/repository/support/JpaMetamodelEntityInformationIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/support/JpaMetamodelEntityInformationIntegrationTests.java @@ -38,6 +38,7 @@ import org.junit.runner.RunWith; import org.springframework.data.jpa.domain.AbstractPersistable; import org.springframework.data.jpa.domain.sample.SampleWithIdClass; import org.springframework.data.jpa.domain.sample.SampleWithIdClassPK; +import org.springframework.data.jpa.domain.sample.SampleWithPrimitiveId; import org.springframework.data.jpa.domain.sample.User; import org.springframework.data.jpa.domain.sample.VersionedUser; import org.springframework.data.repository.core.EntityInformation; @@ -138,6 +139,22 @@ public class JpaMetamodelEntityInformationIntegrationTests { assertThat(information.getIdType(), is((Object) BaseIdClass.class)); } + /** + * @see DATACMNS-357 + */ + @Test + public void detectsNewStateForEntityWithPrimitiveId() { + + EntityInformation information = new JpaMetamodelEntityInformation( + SampleWithPrimitiveId.class, em.getMetamodel()); + + SampleWithPrimitiveId sample = new SampleWithPrimitiveId(); + assertThat(information.isNew(sample), is(true)); + + sample.setId(5L); + assertThat(information.isNew(sample), is(false)); + } + protected String getMetadadataPersitenceUnitName() { return "metadata"; } diff --git a/src/test/resources/META-INF/persistence.xml b/src/test/resources/META-INF/persistence.xml index 397970da4..b91202a06 100644 --- a/src/test/resources/META-INF/persistence.xml +++ b/src/test/resources/META-INF/persistence.xml @@ -14,6 +14,7 @@ org.springframework.data.jpa.domain.sample.SampleEntity org.springframework.data.jpa.domain.sample.SampleEntityPK org.springframework.data.jpa.domain.sample.SampleWithIdClass + org.springframework.data.jpa.domain.sample.SampleWithPrimitiveId org.springframework.data.jpa.domain.sample.VersionedUser org.springframework.data.jpa.domain.sample.AbstractMappedType org.springframework.data.jpa.domain.sample.ConcreteType1