reset password
Author Message
abhishek_sharma
Posts: 79
Posted 17:51 Nov 04, 2013 |

I have a model class which I want to use in different projects. I am not sure where I am doing wrong, if anyone can catch my error.

Project fsmodel - Consists only model class. Eg: AdhocAlbum.java (attached). Maven dependencies

 

Included this project into another project FSWebService

Compiled Successfully. But throwing error at runtime.

SUCCESSFUL PROPERTIES LOAD
Nov 4, 2013 5:43:34 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'fsrest'
Nov 4, 2013 5:43:36 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Nov 4, 2013 5:43:36 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Nov 4, 2013 5:43:36 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 9156 ms
Nov 4, 2013 5:43:36 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [fsrest] in context with path [/pkoapi] threw exception [Request processing failed; nested exception is
org.springframework.dao.InvalidDataAccessApiUsageException: Unknown entity: fsmodel.model.adhoc.AdhocAlbum; nested exception is java.lang.IllegalArgumentException: Unknown entity: fsmodel.model.adhoc.AdhocAlbum] with root cause
org.hibernate.MappingException: Unknown entity: fsmodel.model.adhoc.AdhocAlbum
    at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1192)
    at org.hibernate.internal.SessionImpl.locateEntityPersister(SessionImpl.java:2436)
    at org.hibernate.internal.SessionImpl.access$2100(SessionImpl.java:172)
    at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.<init>(SessionImpl.java:2378)
    at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.<init>(SessionImpl.java:2382)
    at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.<init>(SessionImpl.java:2369)
    at org.hibernate.internal.SessionImpl.byId(SessionImpl.java:1052)
    at org.hibernate.internal.SessionImpl.get(SessionImpl.java:975)
    at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:807)
    at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:781)
    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.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365)
    at com.sun.proxy.$Proxy18.find(Unknown Source)
    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.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
    at com.sun.proxy.$Proxy18.find(Unknown Source)
    at fsrest.model.adhoc.dao.jpa.AdhocAlbumDaoImpl.getAdhocAlbumById(AdhocAlbumDaoImpl.java:24)
    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:319)
    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 com.sun.proxy.$Proxy19.getAdhocAlbumById(Unknown Source)
    at fsrest.webapp.controller.core.HomeController.index(HomeController.java:23)

 


 

Attachments:
cysun
Posts: 2935
Posted 20:13 Nov 04, 2013 |

When Hibernate starts (as a JPA provider), it scans classpath for Entity classes (i.e. classes annotated with @Entity). My guess is that it's only scanning the classpath of the current project but not the included one.

You can try explicitly including the entity classes in persistence.xml (see here for an example) and see if it helps.

abhishek_sharma
Posts: 79
Posted 12:58 Nov 05, 2013 |

I don't have any Entity Classes in my FSWebService Project. All classes are in FSModel Project.

Example do make  sense though  I haven't tried it yet. I will definitely implement it, but just wondering if I end up having 100 classes then I have to explicitly include it in persistence.xml

Thanks for the reply, I may ask few things to proceed in right direction