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

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

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/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"/commerce-legacy/>
            <discriminator-column name="ORDERTYPE" discriminator-type="STRING"/commerce-legacy/>
        </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:
                      CoreTutorial3/ext-core/src/main/resources/META-INF/jpa-persistence.xml
    	<persistence-unit name="commerce-persistence-unit">
    		<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    		<!-- Add new mapping files (*-orm.xml) here. -->
    		<!-- reference to new mapping file: -->
    		<mapping-file>META-INF/ext-order-orm.xml</mapping-file>
    
    		<!-- class declarations follow here -->
    		<!-- Add entities here. -->
    		<class>com.extensions.domain.order.impl.ExtOrderImpl</class>
    		<exclude-unlisted-classes>true</exclude-unlisted-classes>
    		<properties>
    			<!-- Default ConnectionFactoryName has changed in 6.4.  It can be overridden by a custom
    				   jpa-persistence.xml in a jar in the classpath after ep-core.  However recommended
    				   practice is to use the new name or setup a JNDI alias.  -->
    			<property name="openjpa.ConnectionFactoryName" value="java:comp/env/jdbc/epjndi"/commerce-legacy/>
    			<property name="openjpa.Log" value="commons"/commerce-legacy/>
    			<property name="openjpa.ConnectionFactoryProperties"
    				value="PrettyPrint=true, PrettyPrintLineLength=120"/commerce-legacy/>
    			<property name="openjpa.jdbc.EagerFetchMode" value="parallel"/commerce-legacy/>
    			<property name="openjpa.jdbc.SubclassFetchMode" value="parallel"/commerce-legacy/>
    			<property name="openjpa.DetachState" value="loaded(DetachedStateField=true)"/commerce-legacy/>
    			<property name="openjpa.Multithreaded" value="true"/commerce-legacy/>
    			<property name="openjpa.AutoDetach" value="close, commit, nontx-read"/commerce-legacy/>
    			<property name="openjpa.jdbc.DBDictionary"
    				value="SupportsSubselect=true, SupportsCorrelatedSubselect=false"/commerce-legacy/>
    
    			<property name="openjpa.DataCacheManager" value="ehcache"/commerce-legacy/>
    
    			<property name="openjpa.QueryCompilationCache"
    				value="true(cacheSize=2500,softReferenceSize=0)"/commerce-legacy/>
    			<property name="openjpa.QueryCache" value="true(cacheSize=10000,softReferenceSize=0)"/commerce-legacy/>
    			<property name="openjpa.jdbc.QuerySQLCache" value="false"/commerce-legacy/>
    		</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