Hi everyone.
Till today I have done my projects always and completely with Roo, but now I'm starting to use it only for handle getters and setters creation (@RooJavaBean).
So I have to handle the DAOs myself.
My problem is explained below:
I have an abstract class VerbaleMt, extended by an abstract class VerbaleMtB, extended by a class VerbaleMtBTT.
Code:@RooJavaBean @Entity @Table(name="ext_verbale_MT") @Inheritance(strategy=javax.persistence.InheritanceType.JOINED) public abstract class VerbaleMt implements DomainObject { .... } @RooJavaBean @Entity @Inheritance(strategy=javax.persistence.InheritanceType.JOINED) @Table(name="ext_verbale_MT_B") public abstract class VerbaleMtB extends VerbaleMt implements DomainObject { ... } @RooJavaBean @Inheritance(strategy=javax.persistence.InheritanceType.JOINED) @Table(name="ext_verbale_MT_B_TT") @Entity public class VerbaleMtBTT extends VerbaleMtB{ .... }
So here is my dao interface and implementation
Observing what Roo do, I've implemented the DAO for the first abstract class inherited: VerbaleMt.Code:public interface GenericDao <T extends DomainObject> { public T get(Long id); public List<T> getAll(); public void save(T object); public void delete (T object); } public class GenericDaoJpa<T extends DomainObject> implements GenericDao<T> { private Class<T> type; @PersistenceContext protected EntityManager entityManager; public GenericDaoJpa(Class<T> type) { super(); this.type = type; } public T get(Long id) { return (T) entityManager.find(type, id); } public List<T> getAll() { Query query = entityManager.createQuery("select obj from " + type.getName() + " obj"); return query.getResultList(); } public void save(T object) throws DataAccessException { entityManager.persist(object); } public void delete(T object) throws DataAccessException { entityManager.remove(object); } }
I've also configured "verbaleMtDao" used by @Repository annotation.Code:@Repository("verbaleMtDao") public class VerbaleMtDaoJpa extends GenericDaoJpa<VerbaleMt> implements VerbaleMtDao { public VerbaleMtDaoJpa() { super(VerbaleMt.class); } }
In testing phase all goes right except one thing! I can insert and remove instances of VerbaleMtBTT from my DB.. but I cannot list elements.
Code:@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:/META-INF/spring/spring-master.xml" }) @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false) @Transactional public class VerbaleMtBTTDaoTest { VerbaleMtBTT verbaleMtBTT; @Autowired VerbaleMtDao verbaleMtDao; @Before public void initializeTest(){ verbaleMtBTT = new VerbaleMtBTT(); verbaleMtBTT.setAnnoimp((short)2010); verbaleMtBTT.setCondnudiso("Isolato"); verbaleMtDao.save(verbaleMtBTT); } @After public void finalizeTest(){ verbaleMtDao.delete(verbaleMtBTT); verbaleMtDao = null; } @Test public void testMessagePersisted(){ --->> final List<VerbaleMt> messaggi = verbaleMtDao.getAll(); Assert.assertTrue(messaggi.size() > 1); } }
When I call verbaleMtDao.getAll(); it throws an exception:
Surely it is an error of mine.. but I don't find where..Code:org.springframework.orm.jpa.JpaSystemException: org.hibernate.InstantiationException: Cannot instantiate abstract class or interface: it.cpmapave.mt.verbali.domain.VerbaleMtB; nested exception is javax.persistence.PersistenceException: org.hibernate.InstantiationException: Cannot instantiate abstract class or interface: it.cpmapave.mt.verbali.domain.VerbaleMtB at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:311) at org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect.ajc$afterThrowing$org_springframework_orm_jpa_aspectj_JpaExceptionTranslatorAspect$1$18a1ac9(JpaExceptionTranslatorAspect.aj:15) at it.cpmapave.mt.verbali.dao.jpa.GenericDaoJpa.getAll(GenericDaoJpa.java:35) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy26.getAll(Unknown Source) at .......
can someone please give me a help?
Thank you
Marco


Reply With Quote