diff --git a/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/stringcast/DummyEntity.java b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/stringcast/Message.java similarity index 76% rename from persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/stringcast/DummyEntity.java rename to persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/stringcast/Message.java index 12b57ff112..fb521cfea6 100644 --- a/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/stringcast/DummyEntity.java +++ b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/stringcast/Message.java @@ -3,13 +3,12 @@ package com.baeldung.jpa.stringcast; import javax.persistence.*; @SqlResultSetMapping(name = "textQueryMapping", classes = { - @ConstructorResult(targetClass = DummyEntity.class, columns = { + @ConstructorResult(targetClass = Message.class, columns = { @ColumnResult(name = "text") }) }) @Entity -@Table(name = "dummy") -public class DummyEntity { +public class Message { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -17,11 +16,11 @@ public class DummyEntity { private String text; - public DummyEntity() { + public Message() { } - public DummyEntity(String text) { + public Message(String text) { this.text = text; } diff --git a/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml b/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml index 6345e7f364..3fdc8ce27c 100644 --- a/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml +++ b/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml @@ -23,7 +23,7 @@ org.hibernate.jpa.HibernatePersistenceProvider - com.baeldung.jpa.stringcast.DummyEntity + com.baeldung.jpa.stringcast.Message diff --git a/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/stringcast/SpringCastUnitTest.java b/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/stringcast/SpringCastUnitTest.java index d9c3adef26..0a11725fc3 100644 --- a/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/stringcast/SpringCastUnitTest.java +++ b/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/stringcast/SpringCastUnitTest.java @@ -3,10 +3,7 @@ package com.baeldung.jpa.stringcast; import org.junit.BeforeClass; import org.junit.Test; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.EntityTransaction; -import javax.persistence.Persistence; +import javax.persistence.*; import java.util.List; import static org.junit.Assert.assertEquals; @@ -22,18 +19,18 @@ public class SpringCastUnitTest { em = emFactory.createEntityManager(); // insert an object into the db - DummyEntity dummyEntity = new DummyEntity(); - dummyEntity.setText("text"); + Message message = new Message(); + message.setText("text"); EntityTransaction tr = em.getTransaction(); tr.begin(); - em.persist(dummyEntity); + em.persist(message); tr.commit(); } @Test(expected = ClassCastException.class) public void givenExecutorNoCastCheck_whenQueryReturnsOneColumn_thenClassCastThrown() { - List results = QueryExecutor.executeNativeQueryNoCastCheck("select text from dummy", em); + List results = QueryExecutor.executeNativeQueryNoCastCheck("select text from message", em); // fails for (String[] row : results) { @@ -43,13 +40,13 @@ public class SpringCastUnitTest { @Test public void givenExecutorWithCastCheck_whenQueryReturnsOneColumn_thenNoClassCastThrown() { - List results = QueryExecutor.executeNativeQueryWithCastCheck("select text from dummy", em); + List results = QueryExecutor.executeNativeQueryWithCastCheck("select text from message", em); assertEquals("text", results.get(0)[0]); } @Test public void givenExecutorGeneric_whenQueryReturnsOneColumn_thenNoClassCastThrown() { - List results = QueryExecutor.executeNativeQueryGeneric("select text from dummy", "textQueryMapping", em); + List results = QueryExecutor.executeNativeQueryGeneric("select text from message", "textQueryMapping", em); assertEquals("text", results.get(0).getText()); } diff --git a/persistence-modules/java-jpa/src/test/resources/persistence.xml b/persistence-modules/java-jpa/src/test/resources/persistence.xml index b6cc51c3b3..c902e0a320 100644 --- a/persistence-modules/java-jpa/src/test/resources/persistence.xml +++ b/persistence-modules/java-jpa/src/test/resources/persistence.xml @@ -20,7 +20,7 @@ org.hibernate.jpa.HibernatePersistenceProvider - com.baeldung.jpa.stringcast.DummyEntity + com.baeldung.jpa.stringcast.Message