Page 1 of 2

Extending Domain

Posted: Tue Sep 11, 2012 1:08 pm
by ganu98
Domain extension issue.
@Entity
@EntityListeners(value = { AdminAuditableListener.class })
public class HubProductImpl extends ProductImpl implements HubProduct{
---
getter
setter
}

DemoSite\core\src\main\resources\applicationcontext.xml
------------------------------
<bean id="blPersistenceUnitManager"
class="org.broadleafcommerce.common.extensibility.jpa.MergePersistenceUnitManager">
<property name="loadTimeWeaver">
<set>
<bean
class="org.broadleafcommerce.common.extensibility.jpa.BroadleafLoadTimeWeaver" />
</set>
</property>
</bean>

Persistance-admin.xml & persistance.xml
--------------------
<persistence-unit name="blPU" transaction-type="RESOURCE_LOCAL">
<non-jta-data-source>jdbc/web</non-jta-data-source>
<class>com.myshop.core.catalog.domain.HubProductImpl</class>
<exclude-unlisted-classes/>
<properties>
<property name="broadleaf.ejb.entities.override_single_table"
value="org.broadleafcommerce.core.catalog.domain.ProductImpl"/>
</properties>
</persistence-unit>

[artifact:mvn] Hibernate: select productimp0_.PRODUCT_ID as PRODUCT1_29_, productimp0_.ARCHIVED as ARCHIVED29_, productimp0_.CAN_SELL_WITHOUT_OPTIONS as CAN3_29_, productimp0_.DEFAULT_CATEGORY_ID as DEFAULT10_29_, productimp0_.DEFAULT_SKU_ID as DEFAULT11_29_, productimp0_.DISPLAY_TEMPLATE as DISPLAY4_29_, productimp0_.IS_FEATURED_PRODUCT as IS5_29_, productimp0_.MANUFACTURE as MANUFACT6_29_, productimp0_.MODEL as MODEL29_, productimp0_.URL as URL29_, productimp0_.URL_KEY as URL9_29_, productimp0_1_.AUTO_BUNDLE as AUTO1_30_, productimp0_1_.BUNDLE_PROMOTABLE as BUNDLE2_30_, productimp0_1_.ITEMS_PROMOTABLE as ITEMS3_30_, productimp0_1_.PRICING_MODEL as PRICING4_30_, productimp0_1_.BUNDLE_PRIORITY as BUNDLE5_30_, productimp0_2_.CREATED_BY as CREATED4_128_, productimp0_2_.DATE_CREATED as DATE1_128_, productimp0_2_.DATE_UPDATED as DATE2_128_, productimp0_2_.UPDATED_BY as UPDATED5_128_, case when productimp0_1_.PRODUCT_ID is not null then 1 when productimp0_2_.PRODUCT_ID is not null then 2 when productimp0_.PRODUCT_ID is not null then 0 end as clazz_ from BLC_PRODUCT productimp0_ left outer join BLC_PRODUCT_BUNDLE productimp0_1_ on productimp0_.PRODUCT_ID=productimp0_1_.PRODUCT_ID left outer join HubProductImpl productimp0_2_ on productimp0_.PRODUCT_ID=productimp0_2_.PRODUCT_ID inner join BLC_SKU skuimpl1_ on productimp0_.DEFAULT_SKU_ID=skuimpl1_.SKU_ID left outer join BLC_PRODUCT_SKU_XREF skuimpl1_1_ on skuimpl1_.SKU_ID=skuimpl1_1_.SKU_ID where (productimp0_.ARCHIVED is null or productimp0_.ARCHIVED=?) and skuimpl1_.ACTIVE_START_DATE<? and (skuimpl1_.ACTIVE_END_DATE is null or skuimpl1_.ACTIVE_END_DATE>?)
[artifact:mvn] [ WARN] 23:20:47 JDBCExceptionReporter - SQL Error: 1146, SQLState: 42S02
[artifact:mvn] [ERROR] 23:20:47 JDBCExceptionReporter - Table 'broadleaf.blc_product' doesn't exist
[artifact:mvn] [ERROR] 23:20:47 JobRunShell - Job DEFAULT.rebuildIndexJobDetail threw an unhandled Exception:

Re: Extending Domain

Posted: Tue Sep 11, 2012 3:09 pm
by phillipuniverse
It looks like you're trying to implement the single table inheritance and it looks like you've missed a couple of steps in the process, specifically ensuring that the broadleaf-instrument.jar is registered as a -javaagent JVM parameter. Check out our documentation on this at http://docs.broadleafcommerce.org/curre ... orial.html (scroll down to the last section on "Single table inheritance").

Re: Extending Domain

Posted: Tue Sep 11, 2012 9:58 pm
by ganu98
I have already made below modification in ant script for javaagent. but still its failing

<target name="jetty-demo" depends="start-db">
<delete dir="war/WEB-INF/lib"/>
<artifact:mvn mavenHome="${maven.home}" fork="true">
<jvmarg value="-XX:MaxPermSize=256M" />
<jvmarg value="-Xmx512M" />
<jvmarg value="-Xdebug" />
<jvmarg value="-javaagent:${bl.instr}"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" />
<arg value="compile"/>
<arg value="war:exploded"/>
<arg value="jetty:run"/>
</artifact:mvn>
</target>

Re: Extending Domain

Posted: Tue Sep 11, 2012 10:01 pm
by ganu98
I also made below change for entity
<bean id="org.broadleafcommerce.core.catalog.domain.Product"
class="com.myshop.core.catalog.domain.HubProductImpl"
scope="prototype"/>

Re: Extending Domain

Posted: Tue Sep 11, 2012 10:20 pm
by phillipuniverse
From the aforementioned documentation, this the example given for your persistence.xml file:

Code: Select all

<?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"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
        <!-- Note that this XML will get merged with Broadleaf's internal persistence unit, and your new HotSauceImpl will be added to the managed entities -->
   <persistence-unit name="blPU" transaction-type="RESOURCE_LOCAL">
        <class>com.mycompany.core.catalog.domain.HotSauceImpl</class>
        <class>com.mycompany.core.catalog.domain.CookingClassImpl</class>
        <class>com.mycompany.core.catalog.domain.TShirtImpl</class>
        <class>com.mycompany.core.catalog.domain.GiftBasketImpl</class>
        <exclude-unlisted-classes/>
        <properties>
            ...
            <property name="broadleaf.ejb.entities.override_single_table"
                value="org.broadleafcommerce.core.catalog.domain.ProductImpl"/>
            <property name="broadleaf.ejb.ProductImpl.discriminator.name" value="PRODUCT_TYPE"/>
            <property name="broadleaf.ejb.ProductImpl.discriminator.type" value="STRING"/>
            <property name="broadleaf.ejb.ProductImpl.discriminator.length" value="10"/>
        </properties>
</persistence>


From the code that you listed above, you do not have the other properties like discriminator.name, discriminator.type, etc. Also, in the included code you also do not have your entity annotated with this:

Code: Select all

@Inheritance(discriminatorValue=...)
 


Which is also mentioned in the docs.

In general, the only time you should really need to use single-table is if you have many, many subclasses of ProductImpl. If this is not your use case, I would recommend not using the single-table inheritance.

Re: Extending Domain

Posted: Tue Sep 11, 2012 11:48 pm
by ganu98
I am not adding discriminator Value because i just want to add 4 new column in product table for audit trial(date_added,added_user etc...). Since there is no discriminator value i m not adding extra details

<properties>
...
<property name="broadleaf.ejb.entities.override_single_table"
value="org.broadleafcommerce.core.catalog.domain.ProductImpl"/>
</properties>

My requirement is i need to add audit trail for product(blc_product). for this i am using AdminAudittrial class and its listener. The other alternative i have is go for join table strategy for audit field.In the join strategy case system gives new implementation as different product category in admin GUI while adding product, user has to manually select the new product category. Please suggest which is good

Re: Extending Domain

Posted: Wed Sep 12, 2012 7:25 pm
by ganu98
Hi Guys,
Can you please help me to resolve my requirement.

Thanks in advance

Re: Extending Domain

Posted: Thu Sep 13, 2012 10:23 am
by phillipuniverse
I'm pretty sure that the single-table inheritance will not work in the way that you have described. The fact of the matter is, you still have a subclassed entity. As far as the admin is concerned, either way you'll get an extra option during product creation, since it decides which entities to present based on the class hierarchy itself. Also, since you have a subclassed entity, Hibernate still needs to decide which instance of ProductImpl to actually look up.

But currently, you're getting a problem where the BLC_PRODUCT table isn't even being created at all (it appears that way from the query anyway; you might check the database yourself). Assuming that this is the only table not being created, there is probably an error there because you are excluding those parameters.

Again, I just don't think that what you're trying to make work is going to work.

Re: Extending Domain

Posted: Thu Sep 13, 2012 11:52 am
by ganu98
Thanks a lot phillipuniverse, none of the table got created with this exception. I agree with you, It seems user cannot add any more non discriminator fields in the existing table by extending the basic domain object . Like adding new column for blob or some other attribute to blc_... table. Join table approach is working for me.

The other way Single table approach will work only for discriminator column.

Now my question is how can I avoid an extra option during product creation

Re: Extending Domain

Posted: Thu Sep 13, 2012 1:46 pm
by phillipuniverse
We currently have that on our roadmap and is being tracked in this Jira issue: http://jira.broadleafcommerce.org/browse/BLC-548