Search in sources :

Example 1 with TestSubclassWithSuperclassPk

use of io.crnk.jpa.model.TestSubclassWithSuperclassPk in project crnk-framework by crnk-project.

the class JpaQuerySpecEndToEndTest method testMappedSuperTypeWithPkOnSuperType.

@Test
public void testMappedSuperTypeWithPkOnSuperType() throws InstantiationException, IllegalAccessException {
    ResourceRepositoryV2<TestSubclassWithSuperclassPk, Serializable> repo = client.getQuerySpecRepository(TestSubclassWithSuperclassPk.class);
    ResourceRepositoryV2<RelatedEntity, Serializable> relatedRepo = client.getQuerySpecRepository(RelatedEntity.class);
    RelatedEntity related = new RelatedEntity();
    related.setId(23423L);
    related.setStringValue("test");
    relatedRepo.create(related);
    TestSubclassWithSuperclassPk entity = new TestSubclassWithSuperclassPk();
    entity.setId("test");
    entity.setLongValue(12L);
    entity.setSuperRelatedValue(related);
    repo.create(entity);
    QuerySpec querySpec = new QuerySpec(TestSubclassWithSuperclassPk.class);
    querySpec.includeRelation(Arrays.asList(TestMappedSuperclassWithPk.ATTR_superRelatedValue));
    List<TestSubclassWithSuperclassPk> list = repo.findAll(querySpec);
    Assert.assertEquals(1, list.size());
    TestSubclassWithSuperclassPk testEntity = list.get(0);
    RelatedEntity superRelatedValue = testEntity.getSuperRelatedValue();
    Assert.assertNotNull(superRelatedValue);
}
Also used : TestSubclassWithSuperclassPk(io.crnk.jpa.model.TestSubclassWithSuperclassPk) Serializable(java.io.Serializable) RelatedEntity(io.crnk.jpa.model.RelatedEntity) OtherRelatedEntity(io.crnk.jpa.model.OtherRelatedEntity) QuerySpec(io.crnk.core.queryspec.QuerySpec) AbstractJpaJerseyTest(io.crnk.jpa.AbstractJpaJerseyTest) Test(org.junit.Test)

Aggregations

QuerySpec (io.crnk.core.queryspec.QuerySpec)1 AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)1 OtherRelatedEntity (io.crnk.jpa.model.OtherRelatedEntity)1 RelatedEntity (io.crnk.jpa.model.RelatedEntity)1 TestSubclassWithSuperclassPk (io.crnk.jpa.model.TestSubclassWithSuperclassPk)1 Serializable (java.io.Serializable)1 Test (org.junit.Test)1