OpenJPA
  1. OpenJPA
  2. OPENJPA-1642

ClassCastException caused when using property 'openjpa.Sequence'

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.0.3, 1.2.2, 2.0.0
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      When setting the following property:

      <property name="openjpa.Sequence"
      value="org.apache.openjpa.jdbc.kernel.ClassTableJDBCSeq()"/>

      the following exception is caused:

      java.lang.ClassCastException:
      org.apache.openjpa.conf.OpenJPAConfigurationImpl cannot be cast to
      org.apache.openjpa.jdbc.conf.JDBCConfiguration

      The same exception is caused when using other sequence generators, for example 'org.apache.openjpa.jdbc.kernel.TableJDBCSeq'.

        Issue Links

          Activity

          Hide
          Michael Dick added a comment -

          Pinaki's suggestion to enhance at build time (http://openjpa.208410.n2.nabble.com/DataSource-initialization-error-tt4958860.html#a4980529) should work around the problem. It's not very obvious why that's required.

          The problem is that the PCAgentEnhancer (javaagent) is creates and initializes a new instance of OpenJPAConfigurationImpl, but the Sequence plugin you're using requires a JDBCConfigurationImpl. It's the initialization that causes the problem - we're initializing a plugin that requires more information than we have (e.g. JDBC knowledge).

          Fixing it might be interesting - I'd be tempted to lazily initialize instead of eagerly creating all the plugins. This might break other things though - the code indicates that there once was a threading issue. Failing that we'd have to make OpenJPAConfigurationImpl more fault tolerant which could get a bit thorny too.

          At any rate, please do try enhancing at build time. A good reference can be found here : http://webspherepersistence.blogspot.com/2009/02/openjpa-enhancement.html

          Show
          Michael Dick added a comment - Pinaki's suggestion to enhance at build time ( http://openjpa.208410.n2.nabble.com/DataSource-initialization-error-tt4958860.html#a4980529 ) should work around the problem. It's not very obvious why that's required. The problem is that the PCAgentEnhancer (javaagent) is creates and initializes a new instance of OpenJPAConfigurationImpl, but the Sequence plugin you're using requires a JDBCConfigurationImpl. It's the initialization that causes the problem - we're initializing a plugin that requires more information than we have (e.g. JDBC knowledge). Fixing it might be interesting - I'd be tempted to lazily initialize instead of eagerly creating all the plugins. This might break other things though - the code indicates that there once was a threading issue. Failing that we'd have to make OpenJPAConfigurationImpl more fault tolerant which could get a bit thorny too. At any rate, please do try enhancing at build time. A good reference can be found here : http://webspherepersistence.blogspot.com/2009/02/openjpa-enhancement.html
          Hide
          John added a comment -

          Contents of persistence.xml file:

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

          <!--
          We need to enumerate each persistent class first in the persistence.xml
          See: http://issues.apache.org/jira/browse/OPENJPA-78
          -->
          <persistence-unit name="none" transaction-type="RESOURCE_LOCAL">
          <mapping-file>reversemapping/orm.xml</mapping-file>
          <class>hellojpa.Message</class>
          <class>relations.Deity</class>
          </persistence-unit>

          <!--
          A persistence unit is a set of listed persistent entities as well
          the configuration of an EntityManagerFactory. We configure each
          example in a separate persistence-unit.
          -->
          <persistence-unit name="hellojpa" transaction-type="RESOURCE_LOCAL">
          <!--
          The default provider can be OpenJPA, or some other product.
          This element is optional if OpenJPA is the only JPA provider
          in the current classloading environment, but can be specified
          in cases where there are multiple JPA implementations available.
          -->
          <!--
          <provider>
          org.apache.openjpa.persistence.PersistenceProviderImpl
          </provider>
          -->

          <!-- We must enumerate each entity in the persistence unit -->
          <class>hellojpa.Message</class>

          <properties>
          <!--
          We can configure the default OpenJPA properties here. They
          happen to be commented out here since the provided examples
          all specify the values via System properties.
          -->

          <!--
          <property name="openjpa.ConnectionURL"
          value="jdbc:derby:openjpa-database;create=true"/>
          <property name="openjpa.ConnectionDriverName"
          value="org.apache.derby.jdbc.EmbeddedDriver"/>
          <property name="openjpa.ConnectionUserName"
          value="user"/>
          <property name="openjpa.ConnectionPassword"
          value="secret"/>
          -->
          <property name="openjpa.Sequence" value="org.apache.openjpa.jdbc.kernel.ClassTableJDBCSeq"/>
          </properties>
          </persistence-unit>

          <!-- persistence unit for the "relations" example -->
          <persistence-unit name="relations" transaction-type="RESOURCE_LOCAL">
          <class>relations.Deity</class>
          </persistence-unit>

          <!-- persistence unit for the "reversemapping" example -->
          <persistence-unit name="reversemapping" transaction-type="RESOURCE_LOCAL">
          <mapping-file>reversemapping/orm.xml</mapping-file>
          </persistence-unit>
          <persistence-unit name="embeddables" transaction-type="RESOURCE_LOCAL">
          <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
          <class>embeddables.Address</class>
          <class>embeddables.ContactInfo</class>
          <class>embeddables.Coordinates</class>
          <class>embeddables.Phone</class>
          <class>embeddables.User</class>
          </persistence-unit>
          </persistence>

          Show
          John added a comment - Contents of persistence.xml file: <?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"> <!-- We need to enumerate each persistent class first in the persistence.xml See: http://issues.apache.org/jira/browse/OPENJPA-78 --> <persistence-unit name="none" transaction-type="RESOURCE_LOCAL"> <mapping-file>reversemapping/orm.xml</mapping-file> <class>hellojpa.Message</class> <class>relations.Deity</class> </persistence-unit> <!-- A persistence unit is a set of listed persistent entities as well the configuration of an EntityManagerFactory. We configure each example in a separate persistence-unit. --> <persistence-unit name="hellojpa" transaction-type="RESOURCE_LOCAL"> <!-- The default provider can be OpenJPA, or some other product. This element is optional if OpenJPA is the only JPA provider in the current classloading environment, but can be specified in cases where there are multiple JPA implementations available. --> <!-- <provider> org.apache.openjpa.persistence.PersistenceProviderImpl </provider> --> <!-- We must enumerate each entity in the persistence unit --> <class>hellojpa.Message</class> <properties> <!-- We can configure the default OpenJPA properties here. They happen to be commented out here since the provided examples all specify the values via System properties. --> <!-- <property name="openjpa.ConnectionURL" value="jdbc:derby:openjpa-database;create=true"/> <property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver"/> <property name="openjpa.ConnectionUserName" value="user"/> <property name="openjpa.ConnectionPassword" value="secret"/> --> <property name="openjpa.Sequence" value="org.apache.openjpa.jdbc.kernel.ClassTableJDBCSeq"/> </properties> </persistence-unit> <!-- persistence unit for the "relations" example --> <persistence-unit name="relations" transaction-type="RESOURCE_LOCAL"> <class>relations.Deity</class> </persistence-unit> <!-- persistence unit for the "reversemapping" example --> <persistence-unit name="reversemapping" transaction-type="RESOURCE_LOCAL"> <mapping-file>reversemapping/orm.xml</mapping-file> </persistence-unit> <persistence-unit name="embeddables" transaction-type="RESOURCE_LOCAL"> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> <class>embeddables.Address</class> <class>embeddables.ContactInfo</class> <class>embeddables.Coordinates</class> <class>embeddables.Phone</class> <class>embeddables.User</class> </persistence-unit> </persistence>

            People

            • Assignee:
              Heath Thomann
              Reporter:
              Heath Thomann
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:

                Development