On calling CustomerState.getCustomer() MyCustomerImpl is returned as expected.
But the following throws a ClassCastException
Code: Select all
MyCategoryImpl category = (MyCategoryImpl) request.getAttribute(CategoryHandlerMapping.CURRENT_CATEGORY_ATTRIBUTE_NAME);
Code: Select all
java.lang.ClassCastException: org.broadleafcommerce.core.catalog.domain.CategoryImpl cannot be cast to com.mycompany.domain.MyCategoryImpl
Here is my very basic broadleaf setup.
MyCategoryImpl.java
Code: Select all
@Entity
@Table(name = "MY_CATEGORY")
public class MyCategoryImpl extends CategoryImpl implements Serializable {
@Column(name = "TEST")
protected String test;
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
}
MyCustomerImpl.java
Code: Select all
@Entity
@Table(name = "MY_CUSTOMER")
public class MyCustomerImpl extends CustomerImpl implements Serializable {
@Column(name = "TEST")
protected String test;
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
}
persistence.xml file has
Code: Select all
<class>com.mycompany.domain.MyCustomerImpl</class>
<class>com.mycompany.domain.MyCategoryImpl</class>
and
applicationContext-entity.xml
Code: Select all
<bean id="org.broadleafcommerce.profile.core.domain.Customer" class="com.mycompany.domain.MyCustomerImpl" scope="prototype"/>
<bean id="org.broadleafcommerce.core.catalog.domain.Category" class="com.mycompany.domain.MyCategoryImpl" scope="prototype"/>
The application starts fine and the log has the following.
Is there a reason broaleaf does not allow extending the Category class ? Or am I doing something wrong here ?
Code: Select all
[ INFO] 22:46:24 AnnotationBinder - Binding entity from annotated class: com.mycompany.domain.MyCustomerImpl
...
...
[ INFO] 22:46:33 DefaultListableBeanFactory - Overriding bean definition for bean 'org.broadleafcommerce.profile.core.domain.Customer': replacing [Generic bean: class [org.broadleafcommerce.profile.core.domain.CustomerImpl]; scope=prototype; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [bl-profile-applicationContext-entity.xml]] with [Generic bean: class [com.mycompany.domain.MyCustomerImpl]; scope=prototype; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [applicationContext-entity.xml]]