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/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:
                      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"/>
    			<property name="openjpa.Log" value="commons"/>
    			<property name="openjpa.ConnectionFactoryProperties"
    				value="PrettyPrint=true, PrettyPrintLineLength=120"/>
    			<property name="openjpa.jdbc.EagerFetchMode" value="parallel"/>
    			<property name="openjpa.jdbc.SubclassFetchMode" value="parallel"/>
    			<property name="openjpa.DetachState" value="loaded(DetachedStateField=true)"/>
    			<property name="openjpa.Multithreaded" value="true"/>
    			<property name="openjpa.AutoDetach" value="close, commit, nontx-read"/>
    			<property name="openjpa.jdbc.DBDictionary"
    				value="SupportsSubselect=true, SupportsCorrelatedSubselect=false"/>
    
    			<property name="openjpa.DataCacheManager" value="ehcache"/>
    
    			<property name="openjpa.QueryCompilationCache"
    				value="true(cacheSize=2500,softReferenceSize=0)"/>
    			<property name="openjpa.QueryCache" value="true(cacheSize=10000,softReferenceSize=0)"/>
    			<property name="openjpa.jdbc.QuerySQLCache" value="false"/>
    		</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