-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: how can I load entities from external jar?
PostPosted: Tue Jul 27, 2010 9:38 am 
Newbie

Joined: Mon Dec 14, 2009 5:38 am
Posts: 13
Hello, I have a code below that supposedly to load an entity from an external jar. The jar is not within classpath.

Code:
AnnotationConfiguration ac = new AnnotationConfiguration();
        try {
            File plugin = new File(Executions.getCurrent().getDesktop().getWebApp().getRealPath(Executions.getCurrent().toAbsoluteURI("/plugins/CountriesPlugin.jar", false)).toString());

            ClassLoader cl = URLClassLoader.newInstance(
                    new URL[] { new URL("jar:file://" + plugin.getAbsolutePath() + "!/") },
                    getClass().getClassLoader()
                    );

            Class<?> c = Class.forName("com.exponentum.exponentummis.plugins.CountriesPlugin.entities.Country", true, cl);
            ac.addAnnotatedClass(c);
            ac.buildMappings();
            ac.configure();
            ac.buildSessionFactory();
        } catch (Exception e) {
            e.printStackTrace();
        }


the result from plugin.isExists() is true, therefore my program can read that external jar.
and the result of c is not null, therefore, the class Country can be loaded from that external jar.
but the problem is when I try to ac.buildSessionFactory, it says error like this:

Code:
org.hibernate.MappingException: entity class not found: com.exponentum.exponentummis.plugins.CountriesPlugin.entities.Country
        at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:99)
        at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:168)
        at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
        at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:123)
        at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
        at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
        at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
        at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
        at com.exponentum.exponentummis.core.controller.MainController.loadPlugins(MainController.java:60)
        at com.exponentum.exponentummis.core.controller.MainController.onCreate(MainController.java:43)
        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.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:218)
        at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:140)
        at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1482)
        at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1266)
        at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:422)
        at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:291)
        at org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:238)
        at org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:159)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: com.exponentum.exponentummis.plugins.CountriesPlugin.entities.Country
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1484)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1329)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
        at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:96)
        ... 37 more


what could be the problem?
I'm using tomcat 6.0.24, hibernate 3.2.5, java 1.6.0_20

thanks,
Faizal


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.