1.1 --- a/src/main/java/ru/indvdum/jpa/dao/JPADataAccessObject.groovy Thu Dec 20 19:59:53 2012 +0400
1.2 +++ b/src/main/java/ru/indvdum/jpa/dao/JPADataAccessObject.groovy Sun Dec 23 03:24:53 2012 +0400
1.3 @@ -160,6 +160,7 @@
1.4 }
1.5
1.6 public <T> List<T> list(Class<T> entityClass) {
1.7 + // TODO: check for AbstractEntity type of T
1.8 CriteriaQuery<T> query = em.getCriteriaBuilder().createQuery(entityClass);
1.9 query.from(entityClass);
1.10 return new ArrayList(em.createQuery(query).getResultList());
2.1 --- a/src/test/java/ru/indvdum/jpa/tests/AbstractJPAEntityTest.groovy Thu Dec 20 19:59:53 2012 +0400
2.2 +++ b/src/test/java/ru/indvdum/jpa/tests/AbstractJPAEntityTest.groovy Sun Dec 23 03:24:53 2012 +0400
2.3 @@ -17,7 +17,7 @@
2.4 import org.junit.Test
2.5
2.6 import ru.indvdum.jpa.dao.JPADataAccessObject
2.7 -import ru.indvdum.jpa.entities.AbstractEntity;
2.8 +import ru.indvdum.jpa.entities.AbstractEntity
2.9
2.10
2.11 /**
2.12 @@ -100,6 +100,8 @@
2.13 * @return created entity object
2.14 */
2.15 protected Object createEntity(Class entityClass) {
2.16 + if (entityClass.isInterface())
2.17 + return null;
2.18 assertNotNull entityClass.annotations.find {it instanceof Entity}
2.19 def entity = entityClass.newInstance()
2.20 assert entity.class == entityClass
2.21 @@ -167,10 +169,10 @@
2.22 newValue = type.newInstance(uniqueValue++ % Byte.MAX_VALUE + 1i)
2.23 } else if(type == String.class) {
2.24 newValue = (String) "test${uniqueValue++}"
2.25 - } else if(type instanceof Class && (type as Class).annotations.find {it instanceof Entity} != null) { // modifying of a primary keys is deprecated
2.26 + } 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
2.27 // an attempt to use already created entities
2.28 def currentValue = getFieldValue(entity, field)
2.29 - newValue = toRemove.find {it.class == type && it != currentValue}
2.30 + newValue = toRemove.find {it.class.isAssignableFrom(type) && it != currentValue}
2.31 if(newValue == null)
2.32 newValue = createEntity(type as Class)
2.33 } else if(Enum.class.isAssignableFrom(type)) {