-->
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.  [ 13 posts ] 
Author Message
 Post subject: Hibernate Entity Manager gives me strange Exception
PostPosted: Mon Oct 02, 2006 10:54 am 
Newbie

Joined: Fri Nov 11, 2005 12:29 pm
Posts: 3
Hibernate version:
- Hibernate Core 3.2.0.CR4
- Hibernate Entity Manager 3.2.0.CR2

Mapping documents:
- NONE (Programmatic Configuration)

Code between sessionFactory.openSession() and session.close():
- NONE (Entity Manager)

Full stack trace of any exception that occurs:
Code:
[16:42:42.046] java.lang.IllegalArgumentException: unknown handler key
[16:42:42.046]  at javax.security.jacc.PolicyContext.getContext(PolicyContext.java:280)
[16:42:42.046]  at org.hibernate.secure.JACCPermissions$3.getContextSubject(JACCPermissions.java:88)
[16:42:42.046]  at org.hibernate.secure.JACCPermissions.getContextSubject(JACCPermissions.java:97)
[16:42:42.046]  at org.hibernate.secure.JACCPermissions.checkPermission(JACCPermissions.java:36)
[16:42:42.046]  at org.hibernate.secure.JACCPreLoadEventListener.onPreLoad(JACCPreLoadEventListener.java:30)
[16:42:42.046]  at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:125)
[16:42:42.046]  at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
[16:42:42.046]  at org.hibernate.loader.Loader.doQuery(Loader.java:717)
[16:42:42.046]  at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
[16:42:42.046]  at org.hibernate.loader.Loader.doList(Loader.java:2144)
[16:42:42.046]  at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
[16:42:42.046]  at org.hibernate.loader.Loader.list(Loader.java:2023)
[16:42:42.046]  at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)
[16:42:42.046]  at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
[16:42:42.046]  at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
[16:42:42.046]  at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
[16:42:42.046]  at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
[16:42:42.046]  at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
[16:42:42.046]  at product.test.DummyAction.start(DummyAction.java:33)
[16:42:42.046]  at product.web.action.VelocityAction.handleRequest(VelocityAction.java:40)
[16:42:42.046]  at product.web.ProductRequestHandlerImpl.handleRequest(ProductRequestHandlerImpl.java:42)
[16:42:42.046]  at product.web.ProductServlet2.service(ProductServlet2.java:109)
[16:42:42.046]  at javax.servlet.http.HttpServlet.service(HttpServlet.java:92)
[16:42:42.046]  at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:106)
[16:42:42.046]  at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:209)
[16:42:42.046]  at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:173)
[16:42:42.046]  at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
[16:42:42.046]  at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:274)
[16:42:42.046]  at com.caucho.server.port.TcpConnection.run(TcpConnection.java:511)
[16:42:42.046]  at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:516)
[16:42:42.046]  at com.caucho.util.ThreadPool.run(ThreadPool.java:442)
[16:42:42.046]  at java.lang.Thread.run(Thread.java:595)


Name and version of the database you are using:

Mysql 5.0.22

The generated SQL (show_sql=true):

select testentity0_.id as id0_, testentity0_.name as name0_ from testtest testentity0_


Hi all,

i am already working with hibernate, and i want to switch to the EntityManager.

First try today, and i get this stragen exception. I surfed through the sourcecode, but i dont't have a clue what causes this exception. I configure my EntityManagerFactory programmatically:

Code:
        Ejb3Configuration cfg = new Ejb3Configuration();
       
        cfg.addAnnotatedClass(TestEntity.class);
       
       
        cfg.setProperty("hibernate.show_sql", "true");
        cfg.setProperty("hibernate.hbm2ddl.auto", "update");
        cfg.setProperty("hibernate.bytecode.use_reflection_optimizer", "true");
        cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");

        cfg.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
        cfg.setProperty("hibernate.connection.username", "root");
        cfg.setProperty("hibernate.connection.password", "xxxxx");
        cfg.setProperty("hibernate.connection.url", "jdbc:mysql://localhost/mydb?zeroDateTimeBehavior=round&autoReconnect=true");
        entityManagerFactory = cfg.buildEntityManagerFactory();


the configuration runs fine, but with the first query (em.createQuery()) this exception occurs. My TestEntity has two fields: long id and String name.
The whole thing runs under a servlet, i use a ThreadLocal for my EntityManager instance. The second request to the site causes no exception, but id gets read out of the database (id 1 & id 2), but the getName() method of my testEntity always returns null.

is this a bug?

thank you very much
-- felix


Last edited by felixgonschorek on Tue Dec 01, 2009 4:32 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 09, 2006 4:34 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Are you sure you haven't set up? The JACC listeners should not be enabled by default (unless you have set them up manually).
Code:
hibernate.jacc.enabled

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 22, 2006 2:00 pm 
Regular
Regular

Joined: Sat May 20, 2006 3:49 am
Posts: 78
Hello!

I have had the same problem.

Please try to use the deprecated method createEntityManagerFactory instead of the buildEntityManagerFactory:
Code:
            /** Note: buildEntityManagerFactory seems to have a bug in initialising
             * the JACC-Listeners. We have to use the deprecated method.
             *
             * EntityManagerFactory factory =
             *     (EntityManagerFactory)config.buildEntityManagerFactory();
             */
           
            EntityManagerFactory factory =
                (EntityManagerFactory)config.createEntityManagerFactory();


See also my problem: http://forum.hibernate.org/viewtopic.php?t=967615

Please let me know if that solved your problem.

Regards

Christoph


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 6:03 pm 
Newbie

Joined: Tue Nov 28, 2006 4:03 pm
Posts: 4
I did also run into the same problem with another variation: you get an NPE on EJB3PersistEventListener.invokeSaveLifecycle if you try to persist an entity, and I think I have narrowed the cause, it has to do with the method configure of the EventListenerConfigurator listenerConfigurator instance created in EJB3Configuration constructor not being called, if the EntitMangerFactory is being built through java code rather than via Persitence.xml. Adding

Code:
EventListenerConfigurator listenerConfigurator= new EventListenerConfigurator(cfg);
listenerConfigurator.configure();

before calling buildEntityManagerFactory() would get you by the Exception, this of course is more of highligthing the issue rather than solving it, as mentioned by Christoph in http://forum.hibernate.org/viewtopic.php?t=967615 the deprecated createEntityManagerFactory methods do work as they call private Ejb3Configuration configure(Properties properties, Map workingVars) and listeners among others get initialized, presumably that's what the addXXX configuration methods are for, but it seems that they are not sufficient for a proper EJB3Configuration code construction. I don't know if this qualifies for a Jira entry, but I'll happily add it should it be requested.

Cheers,
Khalil

PS: since this is my first post on a hibernate forum, I won't spare you the customary, but truely felt, you rock guys and keep up the good work!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 04, 2006 5:01 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hi Khalil,
Please open a JIRA issue with a reproducable test case, seems like a bug.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 05, 2006 8:36 pm 
Newbie

Joined: Tue Nov 28, 2006 4:03 pm
Posts: 4
Hi Emmanuel,

I was half way through opening the Jira issue with a TestCase highlighting it, when I noticed that actually I didin't supply a hibernate.cfg.xml and that my code didn't call cfg.configure(String) as shown in the reference documentation. Once I have added an empty Hibernate.cfg.xml file with just the doctype declaration, hibernate-configuration and session-factory empty tags, also the cfg.configure call my failed tests did work. I would still voice the following remark, since this way of building an EntityManagerFactory is supposed to be programatic shoudn't there be a way to do away with XML configuration files altogether, especially if they are empty ones.

Cheers,
Khalil


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 10:47 am 
Regular
Regular

Joined: Sat May 20, 2006 3:49 am
Posts: 78
Have you opened a Jira issue?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 1:44 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
bhmz wrote:
shoudn't there be a way to do away with XML configuration files altogether, especially if they are empty ones.


It should, please open a reproducable testcase :-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 5:15 pm 
Newbie

Joined: Tue Nov 28, 2006 4:03 pm
Posts: 4
Hi Emmanuel,

I have opened Jira issue http://opensource.atlassian.com/project ... se/EJB-257, I hope that the provided TestCase is properly exposing the issue.

Cheers,
Khalil


Top
 Profile  
 
 Post subject: buildEntityManagerFactory() vs createEntityManagerFactory()
PostPosted: Tue Apr 17, 2007 3:18 am 
Newbie

Joined: Tue Apr 17, 2007 3:10 am
Posts: 1
From my experience: buildEntityManagerFactory() does not run EJB3 life cycle events properly such as prePersist(), IF using addClass() to add classes... createEntityManagerFactory() does in fact work correctly, but is deprecated.

where CreateEntityManagerFactory() does in fact invoke these callbacks.

configuration = new Ejb3Configuration();
configuration.configure(Constants.PERSISTENCE_UNIT, null);

// ADD annotated classes...

configuration.addAnnotatedClass(clazz);
...

// DOES NOT RUN LIFECYCLE EVENTS:
entityManagerFactory = configuration.buildEntityManagerFactory();

// WORKS CORRECTLY, BUT DEPRECATED
entityManagerFactory = configuration.createEntityManagerFactory();

Regards,
Falco


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 10:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you need to call configure()
Code:
Ejb3Configuration cfg = new Ejb3Configuration();
Ejb3Configuration configured = cfg.configure( persistenceUnitName, overridenProperties );
EMF emf =  configured != null ? configured.buildEntityManagerFactory() : null;

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 7:43 pm 
Newbie

Joined: Tue Nov 28, 2006 4:03 pm
Posts: 4
Falco,

Which HEM version are you using, starting I believe from 3.3.0GA you wouldn't need to call configure when building an EMF programitcally, in other words not through a persitence.xml file. On the testcase attached to the JIRA issue I have opened, all tests are now passing. If I am not mistaken buildEntityManagerFactory includes a call to configure: configure( (Properties)null, null ); see line 724/728 of Ejb3Configuration V3.3.0GA/V3.3.1GA, thus lifecycle event handlers will be properly initialized when calling buildEntityManagerFactory().

Cheers,
Khalil


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 2:05 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Ah yes, I forgot that bug fix

_________________
Emmanuel


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

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.