# HG changeset patch # User indvdum (gotoindvdum[at]gmail[dot]com) # Date 1356218693 -14400 # Node ID a05948e9458c827966b21ca5f11fad3a85db1c51 # Parent 39381427da3fb736c2086296f0a9137d8d9d9d7b Interface type of fields processing diff -r 39381427da3f -r a05948e9458c src/main/java/ru/indvdum/jpa/dao/JPADataAccessObject.groovy --- a/src/main/java/ru/indvdum/jpa/dao/JPADataAccessObject.groovy Thu Dec 20 19:59:53 2012 +0400 +++ b/src/main/java/ru/indvdum/jpa/dao/JPADataAccessObject.groovy Sun Dec 23 03:24:53 2012 +0400 @@ -160,6 +160,7 @@ } public List list(Class entityClass) { + // TODO: check for AbstractEntity type of T CriteriaQuery query = em.getCriteriaBuilder().createQuery(entityClass); query.from(entityClass); return new ArrayList(em.createQuery(query).getResultList()); diff -r 39381427da3f -r a05948e9458c src/test/java/ru/indvdum/jpa/tests/AbstractJPAEntityTest.groovy --- a/src/test/java/ru/indvdum/jpa/tests/AbstractJPAEntityTest.groovy Thu Dec 20 19:59:53 2012 +0400 +++ b/src/test/java/ru/indvdum/jpa/tests/AbstractJPAEntityTest.groovy Sun Dec 23 03:24:53 2012 +0400 @@ -17,7 +17,7 @@ import org.junit.Test import ru.indvdum.jpa.dao.JPADataAccessObject -import ru.indvdum.jpa.entities.AbstractEntity; +import ru.indvdum.jpa.entities.AbstractEntity /** @@ -100,6 +100,8 @@ * @return created entity object */ protected Object createEntity(Class entityClass) { + if (entityClass.isInterface()) + return null; assertNotNull entityClass.annotations.find {it instanceof Entity} def entity = entityClass.newInstance() assert entity.class == entityClass @@ -167,10 +169,10 @@ newValue = type.newInstance(uniqueValue++ % Byte.MAX_VALUE + 1i) } else if(type == String.class) { newValue = (String) "test${uniqueValue++}" - } else if(type instanceof Class && (type as Class).annotations.find {it instanceof Entity} != null) { // modifying of a primary keys is deprecated + } else if(type instanceof Class && ((type as Class).isInterface() || (type as Class).annotations.find {it instanceof Entity} != null)) { // modifying of a primary keys is deprecated // an attempt to use already created entities def currentValue = getFieldValue(entity, field) - newValue = toRemove.find {it.class == type && it != currentValue} + newValue = toRemove.find {it.class.isAssignableFrom(type) && it != currentValue} if(newValue == null) newValue = createEntity(type as Class) } else if(Enum.class.isAssignableFrom(type)) {