-->
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: JPA stand alone programmatic setup
PostPosted: Mon Apr 02, 2007 9:56 am 
Beginner
Beginner

Joined: Fri Sep 08, 2006 9:41 am
Posts: 23
I'm trying to do a JPA programmatic setup in a stand alone java application. Searching the documentation and web I only found an approach that uses Ejb3Configuration. The steps are simple

Ejb3Configuration cfg = new Ejb3Configuration();
cfg.setProperty("hibernate.show_sql", "true");
...
cfg.setProperty("hibernate.connection.driver_class", "com.informix.jdbc.IfxDriver");
...
cfg.addAnnotatedClass(Article.class);
...
EntityManagerFactory lEntityManagerFactory = cfg.buildEntityManagerFactory();

This works ok. The Article class is loaded and recognized as being an entity:

List lArticles = lEntityManager.createQuery("from Article where articlenr < 103").getResultList();

But then a java.lang.NoClassDefFoundError: javax/security/jacc/EJBMethodPermission occurs... Right. That is a JEE 1.4 method, provided by the container. Which I do not have since this is a stand alone application.

So: how do I do a JPA standalone setup? I do not mind if the startup uses Hibernate code, only that the actual entities are JPA.



Hibernate version: hibernate3.2.0b9

Mapping documents: annotations

Code between sessionFactory.openSession() and session.close(): N/A

Full stack trace of any exception that occurs:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/security/jacc/EJBMethodPermission
at org.hibernate.secure.JACCPreLoadEventListener.onPreLoad(JACCPreLoadEventListener.java:23)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:125)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2157)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2041)
at org.hibernate.loader.Loader.list(Loader.java:2036)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:388)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
at nl.reinders.bm.Test.main(Test.java:45)

Name and version of the database you are using:
Informix 10

The generated SQL (show_sql=true):
Hibernate:
select
article0_.articlenr as articlenr0_,
article0_.description as descript2_0_,
...
from
article article0_
where
articlenr<103


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 02, 2007 3:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
add jacc.jar to your classpath.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 8:48 am 
Beginner
Beginner

Joined: Fri Sep 08, 2006 9:41 am
Posts: 23
max wrote:
add jacc.jar to your classpath.


Rrrrrrright. Well, that was not easy. In the end I found a 8MB jar called jboss-ejb3-all.jar in the caveatemptor-jpa demo.

To the next exception.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 8:51 am 
Beginner
Beginner

Joined: Fri Sep 08, 2006 9:41 am
Posts: 23
tbee wrote:
To the next exception.


Hmmmm.

java.lang.IllegalArgumentException: No PolicyContextHandler for key=javax.security.auth.Subject.container

http://cwiki.apache.org/GMOxDEV/jacc-guide.html

I'm getting the creepy feeling that somewhere I'm trying to emulate a EJB3 container here, which is what I'm trying to avoid.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 8:59 am 
Beginner
Beginner

Joined: Fri Sep 08, 2006 9:41 am
Posts: 23
Exception in thread "main" java.lang.IllegalArgumentException: No PolicyContextHandler for key=javax.security.auth.Subject.container
at javax.security.jacc.PolicyContext.getContext(PolicyContext.java:107)
at org.hibernate.secure.JACCPermissions$3.getContextSubject(JACCPermissions.java:88)
at org.hibernate.secure.JACCPermissions.getContextSubject(JACCPermissions.java:97)
at org.hibernate.secure.JACCPermissions.checkPermission(JACCPermissions.java:36)
at org.hibernate.secure.JACCPreLoadEventListener.onPreLoad(JACCPreLoadEventListener.java:30)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:125)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2157)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2041)
at org.hibernate.loader.Loader.list(Loader.java:2036)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:388)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
at nl.reinders.bm.Test.main(Test.java:49)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 2:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
would it not be simpler to just use the jacc-1_0-fr.jar found in hibernate lib directory that is 24 kb ? :)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 2:52 am 
Beginner
Beginner

Joined: Fri Sep 08, 2006 9:41 am
Posts: 23
max wrote:
would it not be simpler to just use the jacc-1_0-fr.jar found in hibernate lib directory that is 24 kb ? :)


It would if it were there. I'll go out and download another distribution. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 2:53 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
huh ? What distribution are you looking in that does not have that file ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 3:18 am 
Beginner
Beginner

Joined: Fri Sep 08, 2006 9:41 am
Posts: 23
max wrote:
huh ? What distribution are you looking in that does not have that file ?


Nope. Hibernate3.2.0b9 it says here.

The 3.2.3ga release does have the file you mention. When that is used instead of the ejb3-all, the following class is missing:

org/jboss/util/id/SerialVersion

I've unpacked all 3.2.3ga JARs in the lib directory and am searching for a file name like that, but it only finds SerialVersionUID in the javassist jar.

The SerialVersion class is included in the already mentioned 8MB jboss-ejb3-all.jar.

<edit>
The SerialVersion should be available in jboss-common-4.0.2.jar
</edit>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 3:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
tbee wrote:
max wrote:
huh ? What distribution are you looking in that does not have that file ?


Nope. Hibernate3.2.0b9 it says here.


There have never been a release of Hibernate with that name AFAIK.
That looks much more like Hibernate Tools to me!

[qoute]
The 3.2.3ga release does have the file you mention. When that is used instead of the ejb3-all, the following class is missing:

org/jboss/util/id/SerialVersion
[/quote]

Please show the stacktrace so I can see what is actually triggering that error.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 3:57 am 
Beginner
Beginner

Joined: Fri Sep 08, 2006 9:41 am
Posts: 23
max wrote:
Please show the stacktrace so I can see what is actually triggering that error.


Yes, sorry, of course.

Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/util/id/SerialVersion
at javax.security.jacc.EJBMethodPermission.<clinit>(EJBMethodPermission.java:60)
at org.hibernate.secure.JACCPreLoadEventListener.onPreLoad(JACCPreLoadEventListener.java:23)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:125)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
at org.hibernate.loader.Loader.doQuery(Loader.java:729)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
at nl.reinders.bm.Test.main(Test.java:47)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 4:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
If you are just looking for running JPA in J2SE then reading
http://www.hibernate.org/hib_docs/entit ... ml_single/ and searchign for J2SE might be a more efficient way of doing this ;)

use of Ejb3Configuration is more if you want to use the autodiscovery features but not use the JPA API.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 6:09 am 
Beginner
Beginner

Joined: Fri Sep 08, 2006 9:41 am
Posts: 23
max wrote:
If you are just looking for running JPA in J2SE then reading
http://www.hibernate.org/hib_docs/entit ... ml_single/ and searchign for J2SE might be a more efficient way of doing this ;)

use of Ejb3Configuration is more if you want to use the autodiscovery features but not use the JPA API.


I wanted to prevent having to maintain everything multiple times (for dev, test and production). But I've aborted my programmatic setup and will use a hibrate approach:

"The map version is a set of overrides that will take precedence over any properties defined in your persistence.xml files."

The approach still doesn't work, but this will work for me. Thanks for your help.


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.