如何扩展Broadleaf Commerce的客户实体?

时间:2016-09-16 00:19:08

标签: broadleaf-commerce

我试图在我的应用程序中基于DemoSite 5.0.1-GA扩展Customer实体。我扩展了原始的Customer接口和CustomerImpl类。然后将我的CustomerImpl类添加到核心项目中的persistence-core.xml和applicationContext-entity.xml中,用id" org.broadleafcommerce.profile.core.domain.Customer"覆盖bean。

我可以通过这些步骤成功扩展Order实体。但是对于Customer实体,我发现我总是会获得org.broadleafcommerce.profile.core.domain.CustomerImpl的实例,无论是在Order等相关实体中还是直接获得" org.broadleafcommerce.profile.core。 domain.Customer"来自Spring上下文的bean,但不是我预期的扩展类的实例。

这是我的applicationContext-entity.xml,我省略了<beans>元素的属性:

<?xml version="1.0" encoding="UTF-8"?>
<beans>
    <bean id="org.broadleafcommerce.core.order.domain.Order" class="com.ddklife.core.ecommerce.domain.OrderImpl" scope="prototype"/>
    <bean id="com.ddklife.core.autovending.domain.MachineChannel" class="com.ddklife.core.autovending.domain.MachineChannelImpl" scope="prototype"/>
    <bean id="com.ddklife.core.autovending.domain.OrderChannelXref" class="com.ddklife.core.autovending.domain.OrderChannelXrefImpl" scope="prototype"/>
    <bean id="org.broadleafcommerce.profile.core.domain.Customer" class="com.ddklife.core.customer.domain.CustomerImpl" scope="prototype"/>
</beans>

这是我扩展的CustomerImpl类,省略了所有getter / setters方法:

package com.ddklife.core.customer.domain;

@Entity(name = "DdlCustomer")
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "DDL_CUSTOMER")
@NamedQueries({
    @NamedQuery(name="DD_READ_CUSTOMER_BY_WECHATOPENID", query="from DdlCustomer c where weChatOpenId = :weChatOpenId")
})
public class CustomerImpl extends org.broadleafcommerce.profile.core.domain.CustomerImpl implements Customer {

    private static final long serialVersionUID = 1L;

    @Column(name = "DDLIFE_POINTS")
    protected Long ddlifePoints;

    @Column(name = "WECHAT_OPEN_ID")
    protected String weChatOpenId;

}

这是我的扩展OrderImpl类,可以从相对实体或使用Spring上下文的getBean方法正确加载:

package com.ddklife.core.ecommerce.domain;

@Entity(name = "DdlOrder")
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "DDL_ORDER")
public class OrderImpl extends org.broadleafcommerce.core.order.domain.OrderImpl implements Order {

    private static final long serialVersionUID = 1L;

    @Column(name = "STORE_TYPE")
    protected String storeType;

    @Column(name = "STORE_ID")
    protected Long storeId;

    @Column(name = "PAYMENT_QRCODE_URL")
    protected String paymentQrcodeUrl;

    @OneToMany(fetch = FetchType.LAZY, targetEntity = OrderChannelXrefImpl.class, mappedBy = "order", orphanRemoval = true,
            cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
    protected List<OrderChannelXref> allChannelXrefs = new ArrayList<OrderChannelXref>();

}

2 个答案:

答案 0 :(得分:0)

您可以发布整个applicationContext-entity.xml吗?它应该是这样的:

<bean id="org.broadleafcommerce.profile.core.domain.Customer" class="com.mycompany.core.MyCustomer" scope="prototype" />

可能会发生的事情:

  1. 您在覆盖之前已经有活动会话已经存储了Broadleaf CustomerImpl;尝试清除所有Cookie并重试
  2. 在重建网站之前,您没有进行核心项目的mvn安装。战争档案。当您构建站点项目时,您需要确保包含核心项目。您可以使用root中的Maven命令执行此操作:

    mvn -pl site -am clean install

  3. 这将确保&#39;网站&#39;模块及其依赖项(如核心)重建

答案 1 :(得分:0)

您需要将新实体添加到: /core/src/main/resources/META-INF/persistence-core.xml

<persistence-unit name="blPU" transaction-type="RESOURCE_LOCAL">
    ...
    <class>com.mycompany.order.domain.MyOrderImpl</class>
    ...
</persistence-unit>