eireshop.ie

20/07/2008 - official start of beta testing.

YarentY

www.yarenty.com - projects incubator

JPA – OSGi – Hibernate – JDK6 (part 1) - hack PDF Print E-mail
Written by yarenty   
Thursday, 25 June 2009 11:40
Article Index
JPA – OSGi – Hibernate – JDK6 (part 1)
Running in OSGi container
Hacking Hibernate bundles
All Pages

 


Hack:

-          I put my persistence.xml into hibernate-ejb fragment bundle, as EntityManager is there.

-          Add DynamicImport-Package:* into hibernate Metainf.fm file.

 

 

osgi> Persistence bundle starting...

Persistence bundle started.

Registering persistence provider ;-)

ProviderTracker: New service detected...

ProviderTracker: Added service eireshop

24-Jun-2009 12:43:45 org.slf4j.impl.JCLLoggerAdapter info

INFO: Hibernate Annotations 3.4.0.GA

24-Jun-2009 12:43:45 org.slf4j.impl.JCLLoggerAdapter info

INFO: Hibernate 3.3.1.GA

24-Jun-2009 12:43:45 org.slf4j.impl.JCLLoggerAdapter info

INFO: hibernate.properties not found

24-Jun-2009 12:43:45 org.slf4j.impl.JCLLoggerAdapter info

INFO: Bytecode provider name : javassist

24-Jun-2009 12:43:45 org.slf4j.impl.JCLLoggerAdapter info

INFO: using JDK 1.4 java.sql.Timestamp handling

24-Jun-2009 12:43:45 org.slf4j.impl.JCLLoggerAdapter info

INFO: Hibernate EntityManager 3.4.0.GA

24-Jun-2009 12:43:45 org.slf4j.impl.JCLLoggerAdapter warn

INFO: Binding entity from annotated class: com.yarenty.eireshop.domain.User

24-Jun-2009 12:43:45 org.slf4j.impl.JCLLoggerAdapter info

INFO: Bind entity com.yarenty.eireshop.domain.User on table eire_users

24-Jun-2009 12:43:45 org.slf4j.impl.JCLLoggerAdapter info

INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory

24-Jun-2009 12:43:46 org.slf4j.impl.JCLLoggerAdapter info

INFO: Using ASTQueryTranslatorFactory

[..]

24-Jun-2009 12:43:46 org.slf4j.impl.JCLLoggerAdapter info

INFO: table found: ncards_jvd.eire_users

24-Jun-2009 12:43:46 org.slf4j.impl.JCLLoggerAdapter info

INFO: columns: [id, username, created, email, active, class, lastname, firstname, modified, pass, location_id]

24-Jun-2009 12:43:46 org.slf4j.impl.JCLLoggerAdapter info

INFO: foreign keys: []

[..]

24-Jun-2009 12:43:46 org.slf4j.impl.JCLLoggerAdapter info

INFO: table found: ncards_jvd.eire_users

24-Jun-2009 12:43:46 org.slf4j.impl.JCLLoggerAdapter info

INFO: columns: [id, username, created, email, active, class, lastname, firstname, modified, pass, location_id]

24-Jun-2009 12:43:46 org.slf4j.impl.JCLLoggerAdapter info

INFO: indexes: [eire_users_fkindex1, primary, users_index4467]

24-Jun-2009 12:43:46 org.slf4j.impl.JCLLoggerAdapter info

INFO: schema update complete

ProviderTracker: Removing service...

ProviderTracker: Removed service eireshop service object: org.hibernate.ejb.HibernatePersistence@14e45b3

 

 

As long it looks pretty good. Let display something in that view:

 

            List<User> users;

            users = new UserHome().getAll();

 

            for (User user2 : users) {

                  System.out.println(user2);

            }

 

 

After start instead of output I get:

org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken [ from com.yarenty.eireshop.domain.User user ]

            at org.hibernate.hql.ast.HqlLexer.panic(HqlLexer.java:80)

            at antlr.CharScanner.setTokenObjectClass(CharScanner.java:338)

            at org.hibernate.hql.ast.HqlLexer.setTokenObjectClass(HqlLexer.java:54)

 

And reason is – yep, hibernate uses antlr, antlr doesn’t see classes outside its bundle.  Simple solution add DynamicImport-Package:* into antlr Metainf.fm file, better is exactly specify packages that antlr should use, but lets start with simplest solution.

 

And… voile:

 

osgi> Persistence bundle starting...

Persistence bundle started.

Registering persistence provider ;-)

ProviderTracker: New service detected...

ProviderTracker: Added service eireshop

 

[…]

 

ttest3[null] - John Test <test@t.t>, created: Wed Jun 24 11:07:27 BST 2009

ttest3[null] - Jan Novack <test@t.t>, created: Wed Jun 24 11:07:27 BST 2009

jankom2[2] - Janko Muzykant < This e-mail address is being protected from spambots, you need JavaScript enabled to view it >, created: 2008-05-14 00:09:56.0

qwerty[3] - Qwerty Ytrewq < This e-mail address is being protected from spambots, you need JavaScript enabled to view it >, created: 2008-05-23 22:48:17.0

testowy[6] - Testowy Zygmunt < This e-mail address is being protected from spambots, you need JavaScript enabled to view it >, created: 2008-06-11 09:30:40.0

yarenty[7] - Jaroslaw Nowosad < This e-mail address is being protected from spambots, you need JavaScript enabled to view it >, created: 2008-07-05 23:26:55.0

[..]

 

 

 

At end my directory looks like (I changed name to every "hacked" package):

 

com.springsource.com.mysql.jdbc_5.1.6.jar

com.springsource.javassist-3.3.0.ga.jar

com.springsource.javax.activation-1.1.1.jar

com.springsource.javax.ejb-3.0.0.jar

com.springsource.javax.persistence-1.99.0.jar

com.springsource.javax.servlet-2.5.0.jar

com.springsource.javax.transaction-1.1.0.jar

com.springsource.javax.xml.rpc-1.1.0.jar

com.springsource.javax.xml.soap-1.3.0.jar

com.springsource.javax.xml.stream-1.0.1.jar

com.springsource.net.sf.cglib-2.1.3.jar

com.springsource.org.apache.commons.collections-3.2.1.jar

com.springsource.org.apache.commons.logging-1.1.1.jar

com.springsource.org.dom4j-1.6.1.jar

com.springsource.org.hibernate.annotations-3.4.0.GA.jar

com.springsource.org.hibernate.annotations.common-3.3.0.ga.jar

com.springsource.org.hibernate.validator-3.1.0.GA.jar

com.springsource.org.jboss.util-2.0.4.GA.jar

com.springsource.org.jgroups-2.5.1.jar

com.springsource.org.objectweb.asm-1.5.3.jar

com.springsource.org.objectweb.asm.attrs-1.5.3.jar

com.springsource.slf4j.api-1.5.6.jar

com.springsource.slf4j.jcl-1.5.6.jar

 

com.yarenty.antlr-2.7.7.jar

com.yarenty.org.hibernate-3.3.1.GA.jar

com.yarenty.org.hibernate.ejb-3.4.0.GA.jar

 

org.hibernate.ejb-library-3.3.2.GA.libd

 

+ my stuff

+ eclipse RCP stuff

 

 Next part ->don't hack manifest - change hibernate code.



Last Updated ( Thursday, 25 June 2009 13:31 )