Ok, seems like Hibernate class loading interferes with Jenkins plugin class 
loading.

I got it fixed with wrapping the call to hibernate like this:

final ClassLoader contextClassLoader = 
Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
  try {
    // Hibernate behind
    return getIssueRepository().loadIssues(getTopLevelItem(), newAndOpen);
  } finally {
    Thread.currentThread().setContextClassLoader(contextClassLoader);
}

Am Dienstag, 9. Juni 2015 16:56:10 UTC+2 schrieb Michael Prankl:
>
> Hi,
>
> I'm currently working on a plugin that depends on the database-h2-plugin 
> <https://github.com/jenkinsci/database-h2-plugin> and database-plugin 
> <https://github.com/jenkinsci/database-plugin>.
>
> When I try to run a JPA NamedQuery (via PersistenceService from 
> database-plugin), I'm getting a ClassNotFoundException for 
> "org.hibernate.hql.ast.HqlToken". This class is part of hibernate-core, 
> which is a dependency of the database-plugin.
>
> According to the maven dependency-tree of my plugin, the class should be 
> there:
>
> [INFO] --- maven-dependency-plugin:2.3:tree (default-cli) @ codehealth ---
> [INFO] org.jenkins-ci.plugins:codehealth:hpi:1.0-SNAPSHOT
> [INFO] +- org.jenkins-ci.plugins:database:jar:1.3:compile
> [INFO] |  +- commons-dbcp:commons-dbcp:jar:1.4:compile
> [INFO] |  |  \- commons-pool:commons-pool:jar:1.5.4:compile
> [INFO] |  +- org.hibernate:hibernate-entitymanager:jar:3.6.10.Final:compile
> [INFO] |  |  +- cglib:cglib:jar:2.2:compile
> [INFO] |  |  |  \- asm:asm:jar:3.1:compile
> [INFO] |  |  +- javassist:javassist:jar:3.12.0.GA:compile
> [INFO] |  |  +- 
> org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
> [INFO] |  |  \- org.slf4j:slf4j-api:jar:1.6.1:compile
> [INFO] |  \- *org.hibernate:hibernate-core:jar:3.6.10.Final:compile*
> [INFO] |     +- antlr:antlr:jar:2.7.6:compile
> [INFO] |     +- commons-collections:commons-collections:jar:3.2.1:compile
> [INFO] |     +- dom4j:dom4j:jar:1.6.1:compile
> [INFO] |     +- 
> org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile
> [INFO] |     \- javax.transaction:jta:jar:1.1:compile
>
> In some other thread I have read that there can be differences between 
> Jenkins firing up via "hpi:run" or manually via .war file. I tried both 
> ways, and I'm always getting that exception =(
>
> Am I missing some important informations regarding transitive plugin 
> dependencies? Does anyone had similiar problems?
>
> Thanks in advance!
> Michael
>
> Stacktrace:
> [...]
> Caused by: java.lang.IllegalArgumentException: 
> org.hibernate.QueryException: ClassNotFoundException: 
> org.hibernate.hql.ast.HqlToken [select i from 
> org.jenkinsci.plugins.codehealth.model.Issue i where i.currentState.state 
> in (:state0_, :state1_)]
>     at 
> org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1376)
>     at 
> org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1317)
>     at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:255)
>     at 
> org.jenkinsci.plugins.codehealth.service.JPAIssueRepository.loadIssues(JPAIssueRepository.java:205)
>     at 
> org.jenkinsci.plugins.codehealth.action.CodehealthProjectAction.getIssues(CodehealthProjectAction.java:33)
>     ... 75 more
> Caused by: org.hibernate.QueryException: ClassNotFoundException: 
> org.hibernate.hql.ast.HqlToken [select i from 
> org.jenkinsci.plugins.codehealth.model.Issue i where i.currentState.state 
> in (:state0_, :state1_)]
>     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)
>     at antlr.CharScanner.<init>(CharScanner.java:49)
>     at antlr.CharScanner.<init>(CharScanner.java:58)
>     at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:56)
>     at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:53)
>     at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:50)
>     at org.hibernate.hql.ast.HqlLexer.<init>(HqlLexer.java:49)
>     at org.hibernate.hql.ast.HqlParser.getInstance(HqlParser.java:69)
>     at 
> org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:270)
>     at 
> org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:184)
>     at 
> org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138)
>     at 
> org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
>     at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
>     at 
> org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
>     at 
> org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
>     at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1260)
>     at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
>     at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246)
>     ... 77 more
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/c03143e8-a304-448e-9ba8-776aefff9608%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to