J Slick
J Slick

Reputation: 939

Derby IllegalAccessError

Trying to assemble a very small JPA test app using Hibernate, JPA and embedded Derby. Getting an IllegalAccessError from Derby which I have not been able to resolve or find useable info on internet:

Exception in thread "main" java.lang.IllegalAccessError: tried to access method       org.apache.derby.jdbc.EmbeddedDriver.boot()V from class org.apache.derby.jdbc.AutoloadedDriver    

derby.jar 10.9.1.0 is in the class path.

I have successfully set up a similar persistence.xml for my Oracle XE instance, and it works fine.

I am not running any derby network server. I have followed the derby installation instructions and verified the installation. I have used the derby "ij" command-line tool to create and my database (named "swift").

I cannot make sense of this exception and sure would appreciate some new eyes.


ABBREVIATED STACK TRACE:

INFO: HHH000401: using driver [org.apache.derby.jdbc.EmbeddedDriver] at URL       [jdbc:derby:localhost:1527/swift:create-true]
Sep 14, 2012 11:12:00 PM     org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=swift, password=****, autocommit=true, release_mode=auto}
Exception in thread "main" java.lang.IllegalAccessError: tried to access method     org.apache.derby.jdbc.EmbeddedDriver.boot()V from class org.apache.derby.jdbc.AutoloadedDriver
        at org.apache.derby.jdbc.AutoloadedDriver.getDriverModule(Unknown Source)
        at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source)

PERSISTENCE.XML:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns /persistence/persistence_2_0.xsd">

<persistence-unit name="persistenceUnit">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>com.gdeb.swift.NIIN</class>
    <class>com.gdeb.swift.RIC</class>
    <properties>
        <property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.EmbeddedDriver" />
            <property name="hibernate.connection.url" value="jdbc:derby:/swift:create-true" />
            <property name="hibernate.connection.username" value="swift" />
            <property name="hibernate.connection.password" value="swift" />
    </properties>
    </persistence-unit>
</persistence>

Upvotes: 1

Views: 323

Answers (1)

EdC
EdC

Reputation: 2349

This is a bit of a shot in the dark, but hopefully it will point you in the right direction. IllegalAccessError indicates that one class tried to call a method in another class that it's not allowed to access (a private method for example). Obviously in normal situations this would be blocked when compiling, but there are a couple of ways it can come up at runtime. Specifically:

  • If the caller and the callee are different versions, and the method was public in one version and private in another
  • If the caller and the callee are loaded by different classloaders and it's a package protected method. In this case the packages may be considered different because they're loaded in different classloaders.

Some quick googling suggests that there has been a change to the visibility of the boot method in derby. Specifically in 10.0 it is private where as in 10.1.2.1 it is package protected and called from AutoloadedDriver.

Based on this I would say you're being hit by the first case. Have a look and see if you can find more than one version of Derby floating around. It's likely that the AutoloadedDriver is being loaded from one one version of derby, where as the EmbeddedDriver is being loaded from a different jar that's for an earlier version of Derby.

If this is the case, remove the old version of Derby from your classpath.

Upvotes: 1

Related Questions