Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2615

EJB CMP: field mapping ejb attribute with different table column name

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.4.0
    • None
    • Enhance, jpa, kernel
    • None
    • tomee
    • Important

    Description

      Hello OpenJPA community,
      I'm working with CMP ejbs and I have trouble with mappings.
      When my java attribute and table column have the same name, all is allright.
      But when the names are differents, an alter table is done to add a new column with the java attribute name. (and, of course, I can't change database model neither java attributes names)
      example:
      java attribute: annualSalary <=> table column: annual_salary

      Here my openejb-jar.xml, for information:

      <?xml version="1.0" encoding="UTF-8"?>
      <openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1"
      	xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1" xmlns:pkgen="http//www.openejb.org/xml/ns/pkgen-2.0"
      	xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1" xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1">
      
      	<cmp-connection-factory>
      		<resource-link>ejbPool_esd</resource-link>
      	</cmp-connection-factory>
      	<enterprise-beans>
      		<entity>
      			<ejb-name>CustomerEJB</ejb-name>
      			<table-name>CUSTOMER</table-name>
      			<cmp-field-mapping>
      				<cmp-field-name>annualSalary</cmp-field-name>
      				<table-column>annual_salary</table-column>
      			</cmp-field-mapping>
      			<query>
      				<query-method>
      					<method-name>findAll</method-name>
      					<method-params />
      				</query-method>
      				<ejb-ql>SELECT OBJECT(c) FROM CUSTOMER as c</ejb-ql>
      			</query>
      		</entity>
      	</enterprise-beans>
      </openejb-jar>			
      

      So, I'm trying to add annotations on java attributes:

      @Entity
      @Table(name="CUSTOMER")
      public class Customer implements ...
              ....
      	@Column(name="annual_salary")
      	public Double annualSalary;
      

      But, nothing changes.

      So, I'm trying to add an orm.xml file like this:

      <entity-mappings version="1.0" xmlns="http://java.sun.com/xml/ns/persistence/orm"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
          http://java.sun.com/xml/ns/persistence/orm_1_0.xsd">
      	<entity class="........CustomerBean" name="CustomerEJB" access="PROPERTY">
      		<table name="CUSTOMER" />	
      		<attributes>
      			<basic name="annualSalary">
      				<column name="annual_salary" />
      			</basic>
      		</attributes>
      	</entity>
      </entity-mappings>
      

      , but I get an exception:

      org.apache.openejb.OpenEJBException: Creating application failed: K:\apache-tomee-plus-1.7.2\apps\ejb.esd1.0.3: Error building bean 'Customer1EJB'.  Exception:
      class java.lang.ClassFormatError: Code attribute in native or abstract methods in class file .../server/CustomerBean: Code attribut
      e in native or abstract methods in class file .../server/CustomerBean
              at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:970)
              at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:652)
              at org.apache.openejb.assembler.classic.Assembler.buildContainerSystem(Assembler.java:543)
              at org.apache.openejb.assembler.classic.Assembler.build(Assembler.java:439)
              at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:150)
              at org.apache.openejb.OpenEJB.init(OpenEJB.java:298)
              at org.apache.tomee.catalina.TomcatLoader.initialize(TomcatLoader.java:256)
              at org.apache.tomee.catalina.ServerListener.install(ServerListener.java:168)
              at org.apache.tomee.catalina.ServerListener.lifecycleEvent(ServerListener.java:55)
              at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
              at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
              at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:402)
              at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:110)
              at org.apache.catalina.startup.Catalina.load(Catalina.java:638)
              at org.apache.catalina.startup.Catalina.load(Catalina.java:663)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:280)
              at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:454)
      Caused by: org.apache.openejb.OpenEJBException: Error building bean 'CustomerEJB'.  Exception: class java.lang.ClassFormatError: Code attribute in native or ab
      stract methods in class file .../server/CustomerBean: Code attribute in native or abstract methods in class file .../server/CustomerBean
              at org.apache.openejb.assembler.classic.EjbJarBuilder.build(EjbJarBuilder.java:85)
              at org.apache.openejb.assembler.classic.Assembler.initEjbs(Assembler.java:1207)
              at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:837)
              ... 20 more
      Caused by: java.lang.ClassFormatError: Code attribute in native or abstract methods in class file .../server/CustomerBean
              at java.lang.ClassLoader.defineClass1(Native Method)
              at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
              at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
              at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
              at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
              at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
              at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
              at org.apache.openejb.util.classloader.URLClassLoaderFirst.loadInternal(URLClassLoaderFirst.java:168)
              at org.apache.openejb.util.classloader.URLClassLoaderFirst.loadClass(URLClassLoaderFirst.java:117)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:295)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
              at java.lang.Class.forName0(Native Method)
              at java.lang.Class.forName(Class.java:249)
              at org.apache.openejb.assembler.classic.EnterpriseBeanBuilder.load(EnterpriseBeanBuilder.java:420)
              at org.apache.openejb.assembler.classic.EnterpriseBeanBuilder.loadClass(EnterpriseBeanBuilder.java:400)
              at org.apache.openejb.assembler.classic.EnterpriseBeanBuilder.build(EnterpriseBeanBuilder.java:81)
              at org.apache.openejb.assembler.classic.EjbJarBuilder.build(EjbJarBuilder.java:68)
              ... 22 more
      

      Why this error ? and if I change access to use implict access, I get a NullPointerException:

      1000  cmp  WARN   [main] openjpa.Enhance - An exception was thrown while attempting to perform class file transformation on "....ser
      ver.CustomerBean":<openjpa-2.4.0-r422266:1674604 nonfatal general error> org.apache.openjpa.util.GeneralException: An error occurred while enhancing ...server.CustomerBean. Exception message: null
              at org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:578)
              at org.apache.openjpa.enhance.PCClassFileTransformer.transform0(PCClassFileTransformer.java:157)
              at org.apache.openjpa.enhance.PCClassFileTransformer.transform(PCClassFileTransformer.java:127)
              at org.apache.openjpa.persistence.PersistenceProviderImpl$ClassTransformerImpl.transform(PersistenceProviderImpl.java:292)
              at org.apache.openejb.persistence.PersistenceUnitInfoImpl$PersistenceClassFileTransformer.transform(PersistenceUnitInfoImpl.java:362)
              at sun.instrument.TransformerManager.transform(TransformerManager.java:169)
              at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:365)
              at java.lang.ClassLoader.defineClass1(Native Method)
              at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
              at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
              at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
              at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
              at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
              at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
              at org.apache.openejb.util.classloader.URLClassLoaderFirst.loadInternal(URLClassLoaderFirst.java:168)
              at org.apache.openejb.util.classloader.URLClassLoaderFirst.loadClass(URLClassLoaderFirst.java:117)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:295)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
              at java.lang.Class.forName0(Native Method)
              at java.lang.Class.forName(Class.java:249)
              at org.apache.openejb.assembler.classic.EnterpriseBeanBuilder.load(EnterpriseBeanBuilder.java:420)
              at org.apache.openejb.assembler.classic.EnterpriseBeanBuilder.loadClass(EnterpriseBeanBuilder.java:400)
              at org.apache.openejb.assembler.classic.EnterpriseBeanBuilder.build(EnterpriseBeanBuilder.java:81)
              at org.apache.openejb.assembler.classic.EjbJarBuilder.build(EjbJarBuilder.java:68)
              at org.apache.openejb.assembler.classic.Assembler.initEjbs(Assembler.java:1207)
              at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:837)
              at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:652)
              at org.apache.openejb.assembler.classic.Assembler.buildContainerSystem(Assembler.java:543)
              at org.apache.openejb.assembler.classic.Assembler.build(Assembler.java:439)
              at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:150)
              at org.apache.openejb.OpenEJB.init(OpenEJB.java:298)
              at org.apache.tomee.catalina.TomcatLoader.initialize(TomcatLoader.java:256)
              at org.apache.tomee.catalina.ServerListener.install(ServerListener.java:168)
              at org.apache.tomee.catalina.ServerListener.lifecycleEvent(ServerListener.java:55)
              at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
              at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
              at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:402)
              at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:110)
              at org.apache.catalina.startup.Catalina.load(Catalina.java:638)
              at org.apache.catalina.startup.Catalina.load(Catalina.java:663)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:280)
              at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:454)
      Caused by: java.lang.NullPointerException
              at org.apache.openjpa.enhance.PCEnhancer.createGetMethod(PCEnhancer.java:4655)
              at org.apache.openjpa.enhance.PCEnhancer.addGetMethod(PCEnhancer.java:3807)
              at org.apache.openjpa.enhance.PCEnhancer.addAccessors(PCEnhancer.java:3704)
              at org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:567)
              ... 47 more
      

      I don't understand why, and nothing in exception points the defect.

      And I precise I have no dependency on javaee-api-6.0-6.jar.
      (just in tomee lib directory, and nowhere else)

      Attachments

        Activity

          People

            Unassigned Unassigned
            dolu DORE
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: