<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Not visible Interface on persistence query</title><link>https://answers.axonivy.com/questions/945/not-visible-interface-on-persistence-query</link><description>&lt;p&gt;Calling a query on a table with BLOBs (Files in Tables) 
using the jTDS-Driver
I get a class-loader error:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;java.lang.IllegalArgumentException: interface org.hibernate.engine.jdbc.WrappedBlob is not visible from class loader&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;My Solution was to switch to an other classloader:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  public synchronized void method() {

        Thread thread = Thread.currentThread();
        ClassLoader tempLoader = thread.getContextClassLoader();
        thread.setContextClassLoader(null);

        entityManager.createNativeQuery("select * from TSRPTBLB where TSBID = 1 ")
                       .getSingleResult();

        thread.setContextClassLoader(tempLoader);
  }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Will there be any other, cleaner way than switsching the classloader?&lt;/p&gt;
&lt;p&gt;Thank you in advance&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/945/not-visible-interface-on-persistence-query" rel="self"></atom:link><language>en</language><lastBuildDate>Thu, 11 Sep 2014 15:44:18 -0400</lastBuildDate><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/945/not-visible-interface-on-persistence-query/948</link><description>&lt;p&gt;Yes there is a better way: &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;You should explicitly set the correct ClassLoader to a class in the JAR where you run into problems (e.g set the class loader from WrappedBlob.class)&lt;/li&gt;
&lt;li&gt;Add a finally statement so that in case of an exception you can still reset the original context ClassLoader or the server will be in a corrupt state&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;So if you consider both points the code could look as follows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public synchronized void method() {
    Thread thread = Thread.currentThread();
    java.lang.ClassLoader originalClassLoader = thread.getContextClassLoader();
    thread.setContextClassLoader(WrappedBlob.class.getClassLoader());
    try {
        entityManager.createNativeQuery(
                "select * from TSRPTBLB where TSBID = 1 ")
                .getSingleResult();
    } finally {
        thread.setContextClassLoader(originalClassLoader);
    }
}
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Thu, 11 Sep 2014 15:44:18 -0400</pubDate><guid>https://answers.axonivy.com/questions/945/not-visible-interface-on-persistence-query/948</guid></item></channel></rss>