From 60d0d777561e76c031d7638cce011f99b63e886a Mon Sep 17 00:00:00 2001 From: ivelkov Date: Tue, 15 Aug 2017 15:33:18 +0300 Subject: [PATCH 1/3] Improving tests Tests are run against both Hibernate and EclipseLink JPA --- .../rsql/jpa/AbstractVisitorTest.java | 107 ----------------- .../jpa/EntityManagerFactoryInitializer.java | 43 ------- .../tennaito/rsql/jpa/JpaVisitorTest.java | 109 +++++++++++++++--- .../rsql/jpa/TestEntityManagerBuilder.java | 17 +++ src/test/resources/META-INF/persistence.xml | 42 +++---- 5 files changed, 129 insertions(+), 189 deletions(-) delete mode 100644 src/test/java/com/github/tennaito/rsql/jpa/AbstractVisitorTest.java delete mode 100644 src/test/java/com/github/tennaito/rsql/jpa/EntityManagerFactoryInitializer.java create mode 100644 src/test/java/com/github/tennaito/rsql/jpa/TestEntityManagerBuilder.java diff --git a/src/test/java/com/github/tennaito/rsql/jpa/AbstractVisitorTest.java b/src/test/java/com/github/tennaito/rsql/jpa/AbstractVisitorTest.java deleted file mode 100644 index 68916db..0000000 --- a/src/test/java/com/github/tennaito/rsql/jpa/AbstractVisitorTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * The MIT License - * - * Copyright 2015 Antonio Rabelo - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package com.github.tennaito.rsql.jpa; - -import java.util.Date; -import java.util.HashSet; -import java.util.Set; - -import javax.persistence.EntityManager; - -import com.github.tennaito.rsql.jpa.entity.Teacher; -import org.junit.BeforeClass; - -import com.github.tennaito.rsql.jpa.entity.Course; -import com.github.tennaito.rsql.jpa.entity.CourseDetails; -import com.github.tennaito.rsql.jpa.entity.Department; -import com.github.tennaito.rsql.jpa.entity.Person; -import com.github.tennaito.rsql.jpa.entity.Title; - -/** - * @author AntonioRabelo - */ -public abstract class AbstractVisitorTest { - - private static boolean loaded = false; - - protected Class entityClass; - protected EntityManager entityManager; - - @BeforeClass - public static void setUpBefore() throws Exception { - if (!loaded) { - - EntityManager entityManager = EntityManagerFactoryInitializer.getEntityManagerFactory().createEntityManager(); - entityManager.getTransaction().begin(); - - Title title1 = new Title(); - title1.setId(1L); - title1.setName("Phd"); - entityManager.persist(title1); - - Title title2 = new Title(); - title2.setId(2L); - title2.setName("Consultant"); - entityManager.persist(title2); - - Set titles = new HashSet<Title>(); - titles.add(title1); - titles.add(title2); - - Person head = new Person(); - head.setId(1L); - head.setName("Some"); - head.setSurname("One"); - head.setTitles(titles); - entityManager.persist(head); - - Department department = new Department(); - department.setId(1L); - department.setName("Testing"); - department.setCode("MI-MDW"); - department.setHead(head); - entityManager.persist(department); - - Teacher teacher = new Teacher(); - teacher.setId(23L); - teacher.setSpecialtyDescription("Maths"); - entityManager.persist(teacher); - - Course c = new Course(); - c.setId(1L); - c.setCode("MI-MDW"); - c.setActive(true); - c.setCredits(10); - c.setName("Testing Course"); - c.setDepartment(department); - c.setDetails(CourseDetails.of("test")); - c.getDetails().setTeacher(teacher); - c.setStartDate( new Date()); - entityManager.persist(c); - - entityManager.getTransaction().commit(); - loaded = true; - } - } -} diff --git a/src/test/java/com/github/tennaito/rsql/jpa/EntityManagerFactoryInitializer.java b/src/test/java/com/github/tennaito/rsql/jpa/EntityManagerFactoryInitializer.java deleted file mode 100644 index 2ff0c63..0000000 --- a/src/test/java/com/github/tennaito/rsql/jpa/EntityManagerFactoryInitializer.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * The MIT License - * - * Copyright 2015 Antonio Rabelo - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package com.github.tennaito.rsql.jpa; - -import javax.persistence.EntityManagerFactory; -import javax.persistence.Persistence; - -/** - * @author Antonio Rabelo - */ -public class EntityManagerFactoryInitializer { - - private static EntityManagerFactory instance; - - - public static EntityManagerFactory getEntityManagerFactory() { - if (instance != null) return instance; - instance = Persistence.createEntityManagerFactory("persistenceUnit"); - - return instance; - } -} diff --git a/src/test/java/com/github/tennaito/rsql/jpa/JpaVisitorTest.java b/src/test/java/com/github/tennaito/rsql/jpa/JpaVisitorTest.java index c61a0c5..146b349 100644 --- a/src/test/java/com/github/tennaito/rsql/jpa/JpaVisitorTest.java +++ b/src/test/java/com/github/tennaito/rsql/jpa/JpaVisitorTest.java @@ -24,36 +24,38 @@ package com.github.tennaito.rsql.jpa; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertNull; -import static junit.framework.Assert.fail; +import com.github.tennaito.rsql.builder.BuilderTools; +import com.github.tennaito.rsql.jpa.entity.Course; +import com.github.tennaito.rsql.jpa.entity.CourseDetails; +import com.github.tennaito.rsql.jpa.entity.Department; +import com.github.tennaito.rsql.jpa.entity.Person; +import com.github.tennaito.rsql.jpa.entity.Teacher; +import com.github.tennaito.rsql.jpa.entity.Title; +import com.github.tennaito.rsql.misc.SimpleMapper; +import com.github.tennaito.rsql.parser.ast.ComparisonOperatorProxy; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; import javax.persistence.EntityManager; +import javax.persistence.Persistence; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.From; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; -import org.junit.Before; -import org.junit.Test; - -import com.github.tennaito.rsql.builder.BuilderTools; -import com.github.tennaito.rsql.jpa.entity.Course; -import com.github.tennaito.rsql.misc.SimpleMapper; -import com.github.tennaito.rsql.parser.ast.ComparisonOperatorProxy; - import cz.jirutka.rsql.parser.RSQLParser; import cz.jirutka.rsql.parser.ast.AbstractNode; import cz.jirutka.rsql.parser.ast.ComparisonNode; @@ -63,17 +65,88 @@ import cz.jirutka.rsql.parser.ast.Node; import cz.jirutka.rsql.parser.ast.RSQLVisitor; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertNotNull; +import static junit.framework.Assert.assertNull; +import static junit.framework.Assert.fail; + /** * @author AntonioRabelo */ -public class JpaVisitorTest extends AbstractVisitorTest<Course> { +@RunWith(Parameterized.class) +public class JpaVisitorTest { + + @Parameterized.Parameters + public static List<EntityManager[]> data() { + final TestEntityManagerBuilder testEntityManagerBuilder = new TestEntityManagerBuilder(); + final EntityManager eclipseEntityManager = Persistence.createEntityManagerFactory("persistenceUnit-eclipse").createEntityManager(); + final EntityManager hibernateEntityManager = Persistence.createEntityManagerFactory("persistenceUnit-hibernate").createEntityManager(); + initialize(eclipseEntityManager); + initialize(hibernateEntityManager); + return Arrays.asList(new EntityManager[]{eclipseEntityManager}, new EntityManager[]{ hibernateEntityManager}); + } final static XorNode xorNode = new XorNode(new ArrayList<Node>()); - - @Before - public void setUp() throws Exception { - entityManager = EntityManagerFactoryInitializer.getEntityManagerFactory().createEntityManager(); + + private final EntityManager entityManager; + + private Class<Course> entityClass; + + public JpaVisitorTest(EntityManager entityManager) { + this.entityManager = entityManager; entityClass = Course.class; + } + + public static void initialize(EntityManager entityManager) { + entityManager.getTransaction().begin(); + + Title title1 = new Title(); + title1.setId(1L); + title1.setName("Phd"); + entityManager.persist(title1); + + Title title2 = new Title(); + title2.setId(2L); + title2.setName("Consultant"); + entityManager.persist(title2); + + Set<Title> titles = new HashSet<Title>(); + titles.add(title1); + titles.add(title2); + + Person head = new Person(); + head.setId(1L); + head.setName("Some"); + head.setSurname("One"); + head.setTitles(titles); + entityManager.persist(head); + + Department department = new Department(); + department.setId(1L); + department.setName("Testing"); + department.setCode("MI-MDW"); + department.setHead(head); + entityManager.persist(department); + + Teacher teacher = new Teacher(); + teacher.setId(23L); + teacher.setSpecialtyDescription("Maths"); + entityManager.persist(teacher); + + Course c = new Course(); + c.setId(1L); + c.setCode("MI-MDW"); + c.setActive(true); + c.setCredits(10); + c.setName("Testing Course"); + c.setDepartment(department); + c.setDetails(CourseDetails.of("test")); + c.getDetails().setTeacher(teacher); + c.setStartDate(new Date()); + entityManager.persist(c); + + entityManager.getTransaction().commit(); } @Test diff --git a/src/test/java/com/github/tennaito/rsql/jpa/TestEntityManagerBuilder.java b/src/test/java/com/github/tennaito/rsql/jpa/TestEntityManagerBuilder.java new file mode 100644 index 0000000..318407b --- /dev/null +++ b/src/test/java/com/github/tennaito/rsql/jpa/TestEntityManagerBuilder.java @@ -0,0 +1,17 @@ +package com.github.tennaito.rsql.jpa; + +import javax.persistence.EntityManager; +import javax.persistence.Persistence; + +/** + * Created by ivelin on 8/15/17. + */ +public class TestEntityManagerBuilder { + + public EntityManager buildEntityManager(String persistenceUnit) { + final EntityManager entityManager = Persistence.createEntityManagerFactory(persistenceUnit).createEntityManager(); + return entityManager; + } + + +} diff --git a/src/test/resources/META-INF/persistence.xml b/src/test/resources/META-INF/persistence.xml index 215c469..7d0c06e 100644 --- a/src/test/resources/META-INF/persistence.xml +++ b/src/test/resources/META-INF/persistence.xml @@ -4,7 +4,8 @@ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0"> - <persistence-unit name="persistenceUnit"> + + <persistence-unit name="persistenceUnit-eclipse"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <class>com.github.tennaito.rsql.jpa.entity.Course</class> <class>com.github.tennaito.rsql.jpa.entity.Department</class> @@ -13,7 +14,7 @@ <class>com.github.tennaito.rsql.jpa.entity.Teacher</class> <properties> <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" /> - <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:ProductDAOTest" /> + <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:EclipseProductDAOTest" /> <property name="javax.persistence.jdbc.user" value="sa" /> <property name="eclipselink.logging.level" value="FINE" /> <property name="eclipselink.target-database" value="HSQL" /> @@ -24,23 +25,22 @@ <property name="eclipselink.logging.parameters" value="true" /> </properties> </persistence-unit> - - <!-- - <persistence-unit name="persistenceUnit"> - <provider>org.hibernate.ejb.HibernatePersistence</provider> - <class>com.github.tennaito.rsql.jpa.entity.Course</class> - <class>com.github.tennaito.rsql.jpa.entity.Department</class> - <class>com.github.tennaito.rsql.jpa.entity.Person</class> - <class>com.github.tennaito.rsql.jpa.entity.Title</class> - <properties> - <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" /> - <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:ProductDAOTest" /> - <property name="javax.persistence.jdbc.user" value="sa" /> - <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" /> - <property name="hibernate.hbm2ddl.auto" value="create-drop" /> - <property name="hibernate.show_sql" value="true" /> - <property name="hibernate.format_sql" value="true" /> - </properties> - </persistence-unit> - --> + + <persistence-unit name="persistenceUnit-hibernate"> + <provider>org.hibernate.ejb.HibernatePersistence</provider> + <class>com.github.tennaito.rsql.jpa.entity.Course</class> + <class>com.github.tennaito.rsql.jpa.entity.Department</class> + <class>com.github.tennaito.rsql.jpa.entity.Person</class> + <class>com.github.tennaito.rsql.jpa.entity.Title</class> + <properties> + <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" /> + <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:HibernateProductDAOTest" /> + <property name="javax.persistence.jdbc.user" value="sa" /> + <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" /> + <property name="hibernate.hbm2ddl.auto" value="create-drop" /> + <property name="hibernate.show_sql" value="true" /> + <property name="hibernate.format_sql" value="true" /> + </properties> + </persistence-unit> + </persistence> From 7b0d7224e77bc769ddf523d909bc105236060f9d Mon Sep 17 00:00:00 2001 From: ivelkov <ivelkov@axway.com> Date: Tue, 15 Aug 2017 15:44:26 +0300 Subject: [PATCH 2/3] Fixing tests when using hibernate and fixing nested joins + Fixing tests when using hibernate + Fixing an issue where nested joins fail with an IllegalStateException: Illegal attempt to dereference path source + Adding a test case for the nested join --- .../tennaito/rsql/jpa/PredicateBuilder.java | 6 ++-- .../tennaito/rsql/jpa/JpaVisitorTest.java | 30 ++++++++++++++++--- .../tennaito/rsql/jpa/entity/Department.java | 10 +++++++ .../tennaito/rsql/jpa/entity/ObjTags.java | 29 ++++++++++++++++++ .../github/tennaito/rsql/jpa/entity/Tag.java | 27 +++++++++++++++++ src/test/resources/META-INF/persistence.xml | 4 +++ 6 files changed, 99 insertions(+), 7 deletions(-) create mode 100644 src/test/java/com/github/tennaito/rsql/jpa/entity/ObjTags.java create mode 100644 src/test/java/com/github/tennaito/rsql/jpa/entity/Tag.java diff --git a/src/main/java/com/github/tennaito/rsql/jpa/PredicateBuilder.java b/src/main/java/com/github/tennaito/rsql/jpa/PredicateBuilder.java index 01b7c89..2830c7b 100755 --- a/src/main/java/com/github/tennaito/rsql/jpa/PredicateBuilder.java +++ b/src/main/java/com/github/tennaito/rsql/jpa/PredicateBuilder.java @@ -213,10 +213,10 @@ public static <T> Path<?> findPropertyPath(String propertyPath, Path startRoot, classMetadata = metaModel.managedType(associationType); LOG.log(Level.INFO, "Create a join between {0} and {1}.", new Object[]{previousClass, classMetadata.getJavaType().getName()}); - if (root instanceof Join) { - root = root.get(mappedProperty); - } else { + if (root instanceof From) { root = ((From) root).join(mappedProperty); + } else { + root = root.get(mappedProperty); } } else { LOG.log(Level.INFO, "Create property path for type {0} property {1}.", new Object[]{classMetadata.getJavaType().getName(), mappedProperty}); diff --git a/src/test/java/com/github/tennaito/rsql/jpa/JpaVisitorTest.java b/src/test/java/com/github/tennaito/rsql/jpa/JpaVisitorTest.java index 146b349..3e4ca54 100644 --- a/src/test/java/com/github/tennaito/rsql/jpa/JpaVisitorTest.java +++ b/src/test/java/com/github/tennaito/rsql/jpa/JpaVisitorTest.java @@ -28,7 +28,9 @@ import com.github.tennaito.rsql.jpa.entity.Course; import com.github.tennaito.rsql.jpa.entity.CourseDetails; import com.github.tennaito.rsql.jpa.entity.Department; +import com.github.tennaito.rsql.jpa.entity.ObjTags; import com.github.tennaito.rsql.jpa.entity.Person; +import com.github.tennaito.rsql.jpa.entity.Tag; import com.github.tennaito.rsql.jpa.entity.Teacher; import com.github.tennaito.rsql.jpa.entity.Title; import com.github.tennaito.rsql.misc.SimpleMapper; @@ -50,7 +52,6 @@ import java.util.Set; import javax.persistence.EntityManager; -import javax.persistence.Persistence; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.From; import javax.persistence.criteria.Predicate; @@ -80,10 +81,10 @@ public class JpaVisitorTest { @Parameterized.Parameters public static List<EntityManager[]> data() { final TestEntityManagerBuilder testEntityManagerBuilder = new TestEntityManagerBuilder(); - final EntityManager eclipseEntityManager = Persistence.createEntityManagerFactory("persistenceUnit-eclipse").createEntityManager(); - final EntityManager hibernateEntityManager = Persistence.createEntityManagerFactory("persistenceUnit-hibernate").createEntityManager(); + final EntityManager eclipseEntityManager = testEntityManagerBuilder.buildEntityManager("persistenceUnit-eclipse"); initialize(eclipseEntityManager); - initialize(hibernateEntityManager); + final EntityManager hibernateEntityManager = testEntityManagerBuilder.buildEntityManager("persistenceUnit-hibernate"); + initialize(hibernateEntityManager); return Arrays.asList(new EntityManager[]{eclipseEntityManager}, new EntityManager[]{ hibernateEntityManager}); } @@ -122,11 +123,22 @@ public static void initialize(EntityManager entityManager) { head.setTitles(titles); entityManager.persist(head); + Tag tag = new Tag(); + tag.setId(1L); + tag.setTag("TestTag"); + entityManager.persist(tag); + + ObjTags tags = new ObjTags(); + tags.setId(1L); + tags.setTags(Arrays.asList(tag)); + entityManager.persist(tags); + Department department = new Department(); department.setId(1L); department.setName("Testing"); department.setCode("MI-MDW"); department.setHead(head); + department.setTags(tags); entityManager.persist(department); Teacher teacher = new Teacher(); @@ -744,4 +756,14 @@ public void testSelectionUsingEmbeddedAssociationField() throws Exception { List<Course> courses = entityManager.createQuery(query).getResultList(); assertEquals("Testing Course", courses.get(0).getName()); } + + @Test + public void testNestedSelection() throws Exception { + Node rootNode = new RSQLParser().parse("tags.tags.tag=in=(TestTag)"); + RSQLVisitor<CriteriaQuery<Department>, EntityManager> visitor = new JpaCriteriaQueryVisitor<Department>(); + CriteriaQuery<Department> query = rootNode.accept(visitor, entityManager); + + List<Department> departments = entityManager.createQuery(query).getResultList(); + assertEquals("Testing", departments.get(0).getName()); + } } diff --git a/src/test/java/com/github/tennaito/rsql/jpa/entity/Department.java b/src/test/java/com/github/tennaito/rsql/jpa/entity/Department.java index bd64784..4bd2c5f 100644 --- a/src/test/java/com/github/tennaito/rsql/jpa/entity/Department.java +++ b/src/test/java/com/github/tennaito/rsql/jpa/entity/Department.java @@ -27,6 +27,7 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.ManyToOne; +import javax.persistence.OneToOne; /** * @@ -42,6 +43,8 @@ public class Department extends AbstractTestEntity { @ManyToOne private Person head; + @OneToOne + private ObjTags tags; public String getCode() { return code; @@ -59,4 +62,11 @@ public void setHead(Person head) { this.head = head; } + public ObjTags getTags() { + return tags; + } + + public void setTags(ObjTags tags) { + this.tags = tags; + } } diff --git a/src/test/java/com/github/tennaito/rsql/jpa/entity/ObjTags.java b/src/test/java/com/github/tennaito/rsql/jpa/entity/ObjTags.java new file mode 100644 index 0000000..28891f7 --- /dev/null +++ b/src/test/java/com/github/tennaito/rsql/jpa/entity/ObjTags.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) Axway Software, 2017. All Rights Reserved. + * + */ + +package com.github.tennaito.rsql.jpa.entity; + +import java.util.List; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.OneToMany; + + +@Entity +public class ObjTags extends AbstractTestEntity{ + + @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) + private List<Tag> tags; + + public List<Tag> getTags() { + return tags; + } + + public void setTags(List<Tag> tags) { + this.tags = tags; + } +} diff --git a/src/test/java/com/github/tennaito/rsql/jpa/entity/Tag.java b/src/test/java/com/github/tennaito/rsql/jpa/entity/Tag.java new file mode 100644 index 0000000..eb79db6 --- /dev/null +++ b/src/test/java/com/github/tennaito/rsql/jpa/entity/Tag.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) Axway Software, 2017. All Rights Reserved. + * + */ + +package com.github.tennaito.rsql.jpa.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; + +/** + * Created by ivelin on 2/24/17. + */ +@Entity +public class Tag extends AbstractTestEntity { + + @Column(name = "TAG", nullable = false) + private String tag; + + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } +} diff --git a/src/test/resources/META-INF/persistence.xml b/src/test/resources/META-INF/persistence.xml index 7d0c06e..9dfdd4b 100644 --- a/src/test/resources/META-INF/persistence.xml +++ b/src/test/resources/META-INF/persistence.xml @@ -7,6 +7,8 @@ <persistence-unit name="persistenceUnit-eclipse"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + <class>com.github.tennaito.rsql.jpa.entity.Tag</class> + <class>com.github.tennaito.rsql.jpa.entity.ObjTags</class> <class>com.github.tennaito.rsql.jpa.entity.Course</class> <class>com.github.tennaito.rsql.jpa.entity.Department</class> <class>com.github.tennaito.rsql.jpa.entity.Person</class> @@ -28,6 +30,8 @@ <persistence-unit name="persistenceUnit-hibernate"> <provider>org.hibernate.ejb.HibernatePersistence</provider> + <class>com.github.tennaito.rsql.jpa.entity.Tag</class> + <class>com.github.tennaito.rsql.jpa.entity.ObjTags</class> <class>com.github.tennaito.rsql.jpa.entity.Course</class> <class>com.github.tennaito.rsql.jpa.entity.Department</class> <class>com.github.tennaito.rsql.jpa.entity.Person</class> From 811f7c3621902eb08e2948f0deb18438ce8cd9af Mon Sep 17 00:00:00 2001 From: Merlin Fotsing <mnfg@gft.com> Date: Fri, 5 Apr 2019 15:34:19 +0200 Subject: [PATCH 3/3] Updating main dependencies: Hibernate 4.3.10.Final to 5.2.15.Final and replacing org.eclipse.persistence 2.1.0 with org.hibernate.javax.persistence 1.0.0.Final to support ElementCollection in Hibernate 5.2.15.Final --- pom.xml | 274 ++++++++++-------- .../tennaito/rsql/jpa/PredicateBuilder.java | 20 +- .../rsql/jpa/AbstractVisitorTest.java | 73 ++++- .../tennaito/rsql/jpa/JpaVisitorTest.java | 42 ++- .../tennaito/rsql/jpa/entity/Person.java | 14 +- .../rsql/jpa/entity/PersonCourse.java | 61 ++++ src/test/resources/META-INF/persistence.xml | 1 + 7 files changed, 335 insertions(+), 150 deletions(-) create mode 100644 src/test/java/com/github/tennaito/rsql/jpa/entity/PersonCourse.java diff --git a/pom.xml b/pom.xml index 4769ffd..f0e743e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,11 +6,11 @@ <artifactId>rsql-jpa</artifactId> <version>2.0.3-SNAPSHOT</version> <packaging>jar</packaging> - + <!--//////////////////// ABOUT ////////////////////--> <name>RSQL-JPA</name> <inceptionYear>2015</inceptionYear> - <description>A application used to translate RSQL nodes to JPA Criteria Query.</description> + <description>A application used to translate RSQL nodes to JPA Criteria Query.</description> <url>http://github.com/tennaito/rsql-jpa</url> <!--//////////////////// LICENSE ////////////////////--> @@ -20,26 +20,28 @@ <url>http://opensource.org/licenses/MIT</url> </license> </licenses> - + <!--//////////////////// DEVELOPER///////////////////--> <developers> - <developer> - <name>Antonio Rabelo</name> - </developer> - </developers> - - <!--//////////////////// SCM ////////////////////--> + <developer> + <name>Antonio Rabelo</name> + </developer> + </developers> + + <!--//////////////////// SCM ////////////////////--> <scm> <url>https://github.com/tennaito/rsql-jpa/</url> <connection>scm:git:https://github.com/tennaito/rsql-jpa.git</connection> <developerConnection>scm:git:https://github.com/tennaito/rsql-jpa.git</developerConnection> - <tag>HEAD</tag> - </scm> + <tag>HEAD</tag> + </scm> <!--//////////////////// PROPERTIES ////////////////////--> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <maven.compiler.source>1.8</maven.compiler.source> + <maven.compiler.target>1.8</maven.compiler.target> </properties> <!--//////////////////// DEPENDENCIES ////////////////////--> @@ -49,30 +51,30 @@ <dependency> <groupId>cz.jirutka.rsql</groupId> <artifactId>rsql-parser</artifactId> - <version>2.0.0</version> + <version>2.1.0</version> </dependency> - <!-- Unfortunately we don´t have a canonical javax.persistence 2.1 yet --> - <dependency> - <groupId>org.eclipse.persistence</groupId> - <artifactId>javax.persistence</artifactId> - <version>2.1.0</version> - </dependency> + <!-- Unfortunately we don´t have a canonical javax.persistence 2.1 yet --> + <dependency> + <groupId>org.hibernate.javax.persistence</groupId> + <artifactId>hibernate-jpa-2.1-api</artifactId> + <version>1.0.0.Final</version> + </dependency> <!-- Test scope --> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-entitymanager</artifactId> - <version>4.3.10.Final</version> - <scope>test</scope> - </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-entitymanager</artifactId> + <version>5.2.15.Final</version> + <scope>test</scope> + </dependency> - <dependency> - <groupId>org.eclipse.persistence</groupId> - <artifactId>eclipselink</artifactId> - <version>2.6.0-M3</version> - <scope>test</scope> - </dependency> + <dependency> + <groupId>org.eclipse.persistence</groupId> + <artifactId>eclipselink</artifactId> + <version>2.7.4</version> + <scope>test</scope> + </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> @@ -83,7 +85,7 @@ <dependency> <groupId>org.hsqldb</groupId> <artifactId>hsqldb</artifactId> - <version>1.8.0.10</version> + <version>2.4.1</version> <scope>test</scope> </dependency> </dependencies> @@ -92,73 +94,73 @@ <profiles> <profile> - <id>release</id> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-release-plugin</artifactId> - <version>2.5</version> - <configuration> - <autoVersionSubmodules>true</autoVersionSubmodules> - <useReleaseProfile>false</useReleaseProfile> - <releaseProfiles>release</releaseProfiles> - <goals>deploy nexus-staging:release</goals> - </configuration> - </plugin> - <plugin> - <groupId>org.sonatype.plugins</groupId> - <artifactId>nexus-staging-maven-plugin</artifactId> - <version>1.6.3</version> - <extensions>true</extensions> - <configuration> - <serverId>ossrh</serverId> - <nexusUrl>https://oss.sonatype.org/</nexusUrl> - <autoReleaseAfterClose>false</autoReleaseAfterClose> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-source-plugin</artifactId> - <version>2.2.1</version> - <executions> - <execution> - <id>attach-sources</id> - <goals> - <goal>jar-no-fork</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-javadoc-plugin</artifactId> - <version>2.9.1</version> - <executions> - <execution> - <id>attach-javadocs</id> - <goals> - <goal>jar</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-gpg-plugin</artifactId> - <version>1.5</version> - <executions> - <execution> - <id>sign-artifacts</id> - <phase>verify</phase> - <goals> - <goal>sign</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> + <id>release</id> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-release-plugin</artifactId> + <version>2.5.3</version> + <configuration> + <autoVersionSubmodules>true</autoVersionSubmodules> + <useReleaseProfile>false</useReleaseProfile> + <releaseProfiles>release</releaseProfiles> + <goals>deploy nexus-staging:release</goals> + </configuration> + </plugin> + <plugin> + <groupId>org.sonatype.plugins</groupId> + <artifactId>nexus-staging-maven-plugin</artifactId> + <version>1.6.3</version> + <extensions>true</extensions> + <configuration> + <serverId>ossrh</serverId> + <nexusUrl>https://oss.sonatype.org/</nexusUrl> + <autoReleaseAfterClose>false</autoReleaseAfterClose> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-source-plugin</artifactId> + <version>3.0.1</version> + <executions> + <execution> + <id>attach-sources</id> + <goals> + <goal>jar-no-fork</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>3.1.0</version> + <executions> + <execution> + <id>attach-javadocs</id> + <goals> + <goal>jar</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-gpg-plugin</artifactId> + <version>1.6</version> + <executions> + <execution> + <id>sign-artifacts</id> + <phase>verify</phase> + <goals> + <goal>sign</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> </profile> <!-- General profile for CI to analyze code coverage. @@ -188,7 +190,7 @@ <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> - <version>0.7.1.201405082137</version> + <version>0.8.3</version> <executions> <execution> <id>prepare-agent</id> @@ -206,7 +208,7 @@ </plugin> </plugins> </build> - </profile> + </profile> <!-- Profile for Travis CI to use Coveralls. --> @@ -225,7 +227,7 @@ <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> - <version>0.7.1.201405082137</version> + <version>0.8.3</version> <executions> <!-- Merge execution data for unit and integration tests. --> <execution> @@ -257,30 +259,58 @@ <plugin> <groupId>org.eluder.coveralls</groupId> <artifactId>coveralls-maven-plugin</artifactId> - <version>2.2.0</version> + <version>2.2.0</version> </plugin> </plugins> </build> - </profile> + </profile> </profiles> - + <build> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.0</version> + <configuration> + <compilerArgs> + </compilerArgs> + </configuration> + <executions> + <execution> + <id>default-compile</id> + <phase>compile</phase> + <goals> + <goal>compile</goal> + </goals> + </execution> + <execution> + <id>default-testCompile</id> + <phase>test-compile</phase> + <goals> + <goal>testCompile</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + <!--//////////////////// DISTRIBUTION ////////////////////--> - <distributionManagement> - <snapshotRepository> - <id>ossrh</id> - <url>https://oss.sonatype.org/content/repositories/snapshots</url> - </snapshotRepository> - <repository> - <id>ossrh</id> - <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> - </repository> - </distributionManagement> - <ciManagement> - <system>travis</system> - <url>https://travis-ci.org/tennaito/rsql-jpa</url> - </ciManagement> - <issueManagement> - <system>GitHub</system> - <url>https://github.com/tennaito/rsql-jpa/issues</url> - </issueManagement> + <distributionManagement> + <snapshotRepository> + <id>ossrh</id> + <url>https://oss.sonatype.org/content/repositories/snapshots</url> + </snapshotRepository> + <repository> + <id>ossrh</id> + <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> + </repository> + </distributionManagement> + <ciManagement> + <system>travis</system> + <url>https://travis-ci.org/tennaito/rsql-jpa</url> + </ciManagement> + <issueManagement> + <system>GitHub</system> + <url>https://github.com/tennaito/rsql-jpa/issues</url> + </issueManagement> </project> diff --git a/src/main/java/com/github/tennaito/rsql/jpa/PredicateBuilder.java b/src/main/java/com/github/tennaito/rsql/jpa/PredicateBuilder.java index 01b7c89..7c44f39 100755 --- a/src/main/java/com/github/tennaito/rsql/jpa/PredicateBuilder.java +++ b/src/main/java/com/github/tennaito/rsql/jpa/PredicateBuilder.java @@ -207,11 +207,25 @@ public static <T> Path<?> findPropertyPath(String propertyPath, Path startRoot, throw new IllegalArgumentException("Unknown property: " + mappedProperty + " from entity " + classMetadata.getJavaType().getName()); } - if (isAssociationType(mappedProperty, classMetadata)) { + //Add Support of ElementCollection which was forgotten in hibernate version 5.2.15.Final + /** + * see org.hibernate.metamodel.internal.isAssociation() + * public boolean isAssociation() { + * return this.getPersistentAttributeType() == PersistentAttributeType.MANY_TO_ONE || this.getPersistentAttributeType() == PersistentAttributeType.ONE_TO_ONE; + * } + */ + if (isAssociationType(mappedProperty, classMetadata) || + classMetadata.getAttribute(mappedProperty).getPersistentAttributeType() == PersistentAttributeType.ELEMENT_COLLECTION){ + Class<?> associationType = findPropertyType(mappedProperty, classMetadata); String previousClass = classMetadata.getJavaType().getName(); - classMetadata = metaModel.managedType(associationType); - LOG.log(Level.INFO, "Create a join between {0} and {1}.", new Object[]{previousClass, classMetadata.getJavaType().getName()}); + + if (isAssociationType(mappedProperty, classMetadata)) { + classMetadata = metaModel.managedType(associationType); + LOG.log(Level.INFO, "Create a join between {0} and {1}.", new Object[]{previousClass, classMetadata.getJavaType().getName()}); + } else { + LOG.log(Level.INFO, "Create a join between {0} and {1}.", new Object[]{previousClass, mappedProperty}); + } if (root instanceof Join) { root = root.get(mappedProperty); diff --git a/src/test/java/com/github/tennaito/rsql/jpa/AbstractVisitorTest.java b/src/test/java/com/github/tennaito/rsql/jpa/AbstractVisitorTest.java index 68916db..79b9f8f 100644 --- a/src/test/java/com/github/tennaito/rsql/jpa/AbstractVisitorTest.java +++ b/src/test/java/com/github/tennaito/rsql/jpa/AbstractVisitorTest.java @@ -23,21 +23,16 @@ */ package com.github.tennaito.rsql.jpa; +import java.util.Arrays; import java.util.Date; import java.util.HashSet; import java.util.Set; import javax.persistence.EntityManager; -import com.github.tennaito.rsql.jpa.entity.Teacher; +import com.github.tennaito.rsql.jpa.entity.*; import org.junit.BeforeClass; -import com.github.tennaito.rsql.jpa.entity.Course; -import com.github.tennaito.rsql.jpa.entity.CourseDetails; -import com.github.tennaito.rsql.jpa.entity.Department; -import com.github.tennaito.rsql.jpa.entity.Person; -import com.github.tennaito.rsql.jpa.entity.Title; - /** * @author AntonioRabelo */ @@ -45,11 +40,11 @@ public abstract class AbstractVisitorTest<T> { private static boolean loaded = false; - protected Class<T> entityClass; - protected EntityManager entityManager; + Class<T> entityClass; + EntityManager entityManager; @BeforeClass - public static void setUpBefore() throws Exception { + public static void setUpBefore() { if (!loaded) { EntityManager entityManager = EntityManagerFactoryInitializer.getEntityManagerFactory().createEntityManager(); @@ -75,6 +70,20 @@ public static void setUpBefore() throws Exception { head.setSurname("One"); head.setTitles(titles); entityManager.persist(head); + + Person student1 = new Person(); + student1.setId(2L); + student1.setName("Manfred"); + student1.setSurname("Bayo"); + student1.setTitles(titles); + entityManager.persist(student1); + + Person student2 = new Person(); + student2.setId(3L); + student2.setName("Bob"); + student2.setSurname("Dilan"); + student2.setTitles(titles); + entityManager.persist(student2); Department department = new Department(); department.setId(1L); @@ -83,11 +92,23 @@ public static void setUpBefore() throws Exception { department.setHead(head); entityManager.persist(department); + Department department2 = new Department(); + department2.setId(2L); + department2.setName("Testing2"); + department2.setCode("DE-MDW"); + department2.setHead(head); + entityManager.persist(department2); + Teacher teacher = new Teacher(); teacher.setId(23L); teacher.setSpecialtyDescription("Maths"); entityManager.persist(teacher); - + + Teacher teacher2 = new Teacher(); + teacher2.setId(24L); + teacher2.setSpecialtyDescription("Physics"); + entityManager.persist(teacher2); + Course c = new Course(); c.setId(1L); c.setCode("MI-MDW"); @@ -99,6 +120,36 @@ public static void setUpBefore() throws Exception { c.getDetails().setTeacher(teacher); c.setStartDate( new Date()); entityManager.persist(c); + + Course c2 = new Course(); + c2.setId(2L); + c2.setCode("BI-MDW"); + c2.setActive(true); + c2.setCredits(10); + c2.setName("Testing Physics"); + c2.setDepartment(department2); + c2.setDetails(CourseDetails.of("test")); + c2.getDetails().setTeacher(teacher2); + c2.setStartDate( new Date()); + entityManager.persist(c2); + + PersonCourse personCourse = new PersonCourse(); + personCourse.setId(1L); + personCourse.setCode(c.getCode()); + personCourse.setPersonId(student1.getId()); + entityManager.persist(personCourse); + + PersonCourse personCourse2 = new PersonCourse(); + personCourse2.setId(2L); + personCourse2.setCode(c2.getCode()); + personCourse2.setPersonId(student1.getId()); + entityManager.persist(personCourse2); + + PersonCourse personCourse3 = new PersonCourse(); + personCourse3.setId(3L); + personCourse3.setCode(c2.getCode()); + personCourse3.setPersonId(student2.getId()); + entityManager.persist(personCourse3); entityManager.getTransaction().commit(); loaded = true; diff --git a/src/test/java/com/github/tennaito/rsql/jpa/JpaVisitorTest.java b/src/test/java/com/github/tennaito/rsql/jpa/JpaVisitorTest.java index c61a0c5..080a0ad 100644 --- a/src/test/java/com/github/tennaito/rsql/jpa/JpaVisitorTest.java +++ b/src/test/java/com/github/tennaito/rsql/jpa/JpaVisitorTest.java @@ -46,6 +46,7 @@ import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; +import com.github.tennaito.rsql.jpa.entity.Person; import org.junit.Before; import org.junit.Test; @@ -119,7 +120,7 @@ public void testNotEqualSelection() throws Exception { CriteriaQuery<Course> query = rootNode.accept(visitor, entityManager); List<Course> courses = entityManager.createQuery(query).getResultList(); - assertEquals(0, courses.size()); + assertEquals(1, courses.size()); } @Test @@ -129,7 +130,7 @@ public void testGreaterThanSelection() throws Exception { CriteriaQuery<Course> query = rootNode.accept(visitor, entityManager); List<Course> courses = entityManager.createQuery(query).getResultList(); - assertEquals(0, courses.size()); + assertEquals(1, courses.size()); } @Test @@ -139,7 +140,7 @@ public void testGreaterThanDate() throws Exception { CriteriaQuery<Course> query = rootNode.accept(visitor, entityManager); List<Course> courses = entityManager.createQuery(query).getResultList(); - assertEquals(1, courses.size()); + assertEquals(2, courses.size()); } @Test @@ -149,7 +150,7 @@ public void testGreaterThanString() throws Exception { CriteriaQuery<Course> query = rootNode.accept(visitor, entityManager); List<Course> courses = entityManager.createQuery(query).getResultList(); - assertEquals(1, courses.size()); + assertEquals(2, courses.size()); } @Test @@ -194,6 +195,29 @@ public void testGreaterThanEqualSelectionForString() throws Exception { assertEquals("Testing Course", courses.get(0).getName()); } + @Test + public void testEqualSelectionForStringInElementCollection() { + Node rootNode = new RSQLParser().parse("courses=='MI-MDW'"); + RSQLVisitor<CriteriaQuery<Person>, EntityManager> visitor = new JpaCriteriaQueryVisitor<Person>(); + CriteriaQuery<Person> query = rootNode.accept(visitor, entityManager); + + List<Person> courses = entityManager.createQuery(query).getResultList(); + assertEquals(1, courses.size()); + } + + + @Test + public void testEqualSelectionForStringInElementCollectionFailed() { + Node rootNode = new RSQLParser().parse("courses=='DE-MDW'"); + RSQLVisitor<CriteriaQuery<Person>, EntityManager> visitor = new JpaCriteriaQueryVisitor<Person>(); + CriteriaQuery<Person> query = rootNode.accept(visitor, entityManager); + + List<Person> courses = entityManager.createQuery(query).getResultList(); + assertEquals(0, courses.size()); + } + + + @Test public void testGreaterThanEqualNotComparable() throws Exception { try { @@ -233,7 +257,7 @@ public void testLessThanDate() throws Exception { CriteriaQuery<Course> query = rootNode.accept(visitor, entityManager); List<Course> courses = entityManager.createQuery(query).getResultList(); - assertEquals(1, courses.size()); + assertEquals(2, courses.size()); } @Test @@ -243,7 +267,7 @@ public void testLessThanString() throws Exception { CriteriaQuery<Course> query = rootNode.accept(visitor, entityManager); List<Course> courses = entityManager.createQuery(query).getResultList(); - assertEquals(1, courses.size()); + assertEquals(2, courses.size()); } @Test @@ -328,7 +352,7 @@ public void testNotLikeSelection() throws Exception { CriteriaQuery<Course> query = rootNode.accept(visitor, entityManager); List<Course> courses = entityManager.createQuery(query).getResultList(); - assertEquals(0, courses.size()); + assertEquals(1, courses.size()); } @@ -503,7 +527,7 @@ public void testOrSelectionCount() throws Exception { CriteriaQuery<Long> query = rootNode.accept(visitor, entityManager); Long courseCount = entityManager.createQuery(query).getSingleResult(); - assertEquals((Long)1l, courseCount); + assertEquals((Long) 2L, courseCount); } @Test @@ -572,7 +596,7 @@ public void testPrivateConstructor() throws Exception { // When used it returns a instance? assertNotNull(predicateBuilder); } - + ////////////////////////// Mocks ////////////////////////// protected static class OtherNode extends AbstractNode { diff --git a/src/test/java/com/github/tennaito/rsql/jpa/entity/Person.java b/src/test/java/com/github/tennaito/rsql/jpa/entity/Person.java index 5284f62..19d78c4 100644 --- a/src/test/java/com/github/tennaito/rsql/jpa/entity/Person.java +++ b/src/test/java/com/github/tennaito/rsql/jpa/entity/Person.java @@ -24,12 +24,11 @@ */ package com.github.tennaito.rsql.jpa.entity; +import java.util.ArrayList; +import java.util.List; import java.util.Set; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.ManyToMany; +import javax.persistence.*; /** * @@ -44,7 +43,12 @@ public class Person extends AbstractTestEntity { @ManyToMany(cascade=CascadeType.PERSIST) private Set<Title> titles; - + + @ElementCollection(targetClass = String.class) + @CollectionTable(name = "PersonCourse", joinColumns = @JoinColumn(name = "personId")) + @Column(name = "code") + private List<String> courses = new ArrayList<String>(); + public String getSurname() { return surname; } diff --git a/src/test/java/com/github/tennaito/rsql/jpa/entity/PersonCourse.java b/src/test/java/com/github/tennaito/rsql/jpa/entity/PersonCourse.java new file mode 100644 index 0000000..a50a7e2 --- /dev/null +++ b/src/test/java/com/github/tennaito/rsql/jpa/entity/PersonCourse.java @@ -0,0 +1,61 @@ +/* + * The MIT License + * + * Copyright 2013 Jakub Jirutka <jakub@jirutka.cz>. + * Copyright 2015 Antonio Rabelo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.tennaito.rsql.jpa.entity; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.ManyToMany; +import java.util.Set; + +/** + * + * @author Merlin Fotsing + */ +@Entity +public class PersonCourse extends AbstractTestEntity { + + @Column + private Long personId; + + @Column + private String code; + + public Long getPersonId() { + return personId; + } + + public void setPersonId(Long personId) { + this.personId = personId; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } +} diff --git a/src/test/resources/META-INF/persistence.xml b/src/test/resources/META-INF/persistence.xml index 215c469..1f0f4b0 100644 --- a/src/test/resources/META-INF/persistence.xml +++ b/src/test/resources/META-INF/persistence.xml @@ -11,6 +11,7 @@ <class>com.github.tennaito.rsql.jpa.entity.Person</class> <class>com.github.tennaito.rsql.jpa.entity.Title</class> <class>com.github.tennaito.rsql.jpa.entity.Teacher</class> + <class>com.github.tennaito.rsql.jpa.entity.PersonCourse</class> <properties> <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" /> <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:ProductDAOTest" />