Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. The Developer Center continues to support Commerce 6.13.0 through 7.4.1.Visit new site

3 - Updating the Order ORM

3 - Updating the Order ORM

You may have noticed that there are several annotations on the ExtOrderImpl's isAutoBill() method and class. These are Java Persistence API (JPA) annotations that the core's data access layer uses to map Java objects to the correct database tables. In the case of isAutoBill(), the method is mapped to the AUTOBILL column defined in the newly added TORDEREXT table.

Before these JPA annotations will work, you need to update the Order's Object Relational Model (ORM) and JPA settings.

Update the Order ORM

To update the Order's ORM:

  1. Create a file named ext-order-orm.xml in the <Source Code Root>/extensions/core/ext-core/src/main/resources/META-INF directory.
  2. In ext-order-orm.xml, add the following XML:
    <entity-mappings 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" version="1.0">
    
        <package>com.elasticpath.domain.order.impl</package>
        <entity class="OrderImpl">
            <inheritance strategy="JOINED"/>
            <discriminator-column name="ORDERTYPE" discriminator-type="STRING"/>
        </entity>
    
    </entity-mappings>
    This tells JPA to join the TORDER and TORDEREXT tables at runtime.
  3. In ext-core/src/main/resource/META-INF/jpa-persistence.xml, replace <persistence-unit> element with the following:
                      	<persistence-unit name="commerce-persistence-unit">
    		<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    		
    		<!-- Add new mapping files (*-orm.xml) here. You can exclude OOTB files by adding them to persistenceMappingExcludedFiles in spring -->
    		<mapping-file>META-INF/ext-order-orm.xml</mapping-file>
    		
    		<!-- Add entities here. You can remove OOTB entries by adding the classes to persistenceMappingExcludedClasses in spring -->
    		<class>com.extensions.domain.order.impl.ExtOrderImpl</class>
    		
    		<!-- All persistent classes should be listed above and enhanced at runtime.
    		     The following directive supresses runtime enhancement classpath scanning which does not work in an OSGi environment. -->
    		<exclude-unlisted-classes>true</exclude-unlisted-classes>
    		
    		<validation-mode>NONE</validation-mode>
    		
    		<!-- These properties need to be here to ensure enhancement occurs correctly. All other properties
    			 should be added in spring as map entries of persistencePropertyOverrides.
    		 -->
    		<properties>
    			<property name="openjpa.Log" value="slf4j"/>
    			<property name="openjpa.DetachState" value="loaded(DetachedStateField=true)"/>
    		</properties>
    		
    	</persistence-unit>
    
                   
    Note:

    The openjpa.DetachState property is needed to tell the OpenJPA enhancer to maintain attached state across serialization boundaries. If this is not set, objects will contain null (or default) fields after deserialization.

Building the Core Extension Project

Once you have finished configuring the Order ORM, you are ready to build your core extension project.

  • With the command prompt, navigate to the ext-core directory and build the core extension with the following command:
    mvn clean install