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);
}
Aggregations