From 07d15fb39b1ac7e28546ae5a67b387772ffbe33a Mon Sep 17 00:00:00 2001 From: Scott Marlow Date: Tue, 2 Aug 2011 14:08:19 -0400 Subject: [PATCH] HHH-6536, set TCCL to the Hibernate classloader --- .../hibernate/hql/internal/ast/HqlLexer.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/HqlLexer.java b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/HqlLexer.java index fb7bb0c3c2..a21445c5b3 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/HqlLexer.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/HqlLexer.java @@ -23,11 +23,12 @@ * */ package org.hibernate.hql.internal.ast; -import java.io.InputStream; -import java.io.Reader; +import antlr.Token; import org.hibernate.QueryException; import org.hibernate.hql.internal.antlr.HqlBaseLexer; -import antlr.Token; + +import java.io.InputStream; +import java.io.Reader; /** * Custom lexer for the HQL grammar. Extends the base lexer generated by ANTLR @@ -48,8 +49,20 @@ class HqlLexer extends HqlBaseLexer { } public void setTokenObjectClass(String cl) { - // Ignore the token class name parameter, and use a specific token class. - super.setTokenObjectClass( HqlToken.class.getName() ); + Thread thread = null; + ClassLoader contextClassLoader = null; + try { + // workaround HHH-6536, by setting TCCL to the Hibernate classloader + thread = Thread.currentThread(); + contextClassLoader = thread.getContextClassLoader(); + thread.setContextClassLoader(HqlToken.class.getClassLoader()); + + // Ignore the token class name parameter, and use a specific token class. + super.setTokenObjectClass( HqlToken.class.getName() ); + } + finally { + thread.setContextClassLoader( contextClassLoader ); + } } protected void setPossibleID(boolean possibleID) {