问题
Hi I Have extended the Broadleaf Product Entity and added a new attribute to that Entity and added the admin presentation annotation to display on the admin side
Here Is My Code to Extend the entity:
@AdminPresentationMergeOverrides({@AdminPresentationMergeOverride(name = "ExtendProductImpl.productWarranty", mergeEntries = {@AdminPresentationMergeEntry(propertyType = PropertyType.AdminPresentation.EXCLUDED, booleanOverrideValue=false)})})
public class ExtendProductImpl extends ProductImpl implements ExtendProduct {
@Column(name ="PRODUCT_WARRANTY")
@AdminPresentation(friendlyName = "product warrenty",
tab = TabName.General)
private String productWarranty;
public String getProductWarranty() {
return productWarranty;
}
public void setProductWarranty(String productWarranty) {
this.productWarranty = productWarranty;
}}
Here Is my XML files in Core (ApplicationContextEntity.xml) :
http://i.prntscr.com/u2UjARtwRVmI-PswDzxErw.png
Here is the another XML file (Persistant-core) :
http://i.prntscr.com/9Z8y_SplQNKp7HjCw4XyiA.png
Here is the output Screen shot after applying the changes:
http://i.prntscr.com/Gv-ssCaSTa2QbbS5rLB2vg.png
http://i.prntscr.com/eGWugVJRQ-aQqS_heWHsxw.png
Please help me to solve the issue.
Thanks In Advance
回答1:
You need to do 1 more thing and update the demo products to all be of your extended type. The problem is that if you are still relying on the demo data, Hibernate will still treat them as ProductImpl
and not as ExtendProductImpl
.
In your code snippet, you also do not have a @javax.persistence.Entity
or @javax.persistence.Table
annotations. Also, there is generally no need to create an interface for your custom domain object, it is optional. So assuming that it is actually this:
@Entity
@Table(name = "ext_product")
@AdminPresentationMergeOverrides({@AdminPresentationMergeOverride(name = "ExtendProductImpl.productWarranty", mergeEntries = {@AdminPresentationMergeEntry(propertyType = PropertyType.AdminPresentation.EXCLUDED, booleanOverrideValue=false)})})
public class ExtendProductImpl extends ProductImpl implements ExtendProduct {
You should then update the demo data to all be of ExtendProductImpl
type by inserting data into the subclass:
INSERT INTO ext_product (PRODUCT_ID) (SELECT PRODUCT_ID FROM BLC_PRODUCT)
Finally, you might also want to ensure that whenever you create a product in the admin, it should always be of type ExtendProductImpl
. To do this, use @AdminPresentationClass
:
@Entity
@Table(name = "ext_product")
@AdminPresentationClass(ceilingDisplayEntity = "com.mycompany.ExtendProductImpl")
@AdminPresentationMergeOverrides({@AdminPresentationMergeOverride(name = "ExtendProductImpl.productWarranty", mergeEntries = {@AdminPresentationMergeEntry(propertyType = PropertyType.AdminPresentation.EXCLUDED, booleanOverrideValue=false)})})
public class ExtendProductImpl extends ProductImpl implements ExtendProduct {
来源:https://stackoverflow.com/questions/47405796/broadleaf-extending-product-entity-failed