I have successfully setup the Heat Clinic Demo application running on an external Tomcat (version 8) with MYSQL.
I would like to extend a product to include a latitude and longitude value.
I have followed the tutorials for extending entities. The steps followed are below.
I don't see a latitude and longitude field if I attempt to create a product of the new type, called GeoProduct. I'm unsure how these fields will appear in the admin console and the tutorials aren't clear what I should expect.
1. I have created an interface for my new product type in core.
Code: Select all
package com.mycompany.catalog.entity;
import org.broadleafcommerce.core.catalog.domain.Product;
public interface GeoProduct extends Product {
public Double getLat();
public Double getLon();
public void setLon(Double lon);
public void setLat(Double lat);
}
2. I have created the implementation:
Code: Select all
package com.mycompany.catalog.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import org.broadleafcommerce.core.catalog.domain.ProductImpl;
@Entity
@Table(name = "blc_geoproduct")
public class GeoProductImpl extends ProductImpl implements GeoProduct {
private static final long serialVersionUID = 1L;
@Column(name = "LAT")
protected Double lat;
@Column(name = "LON")
protected Double lon;
@Override
public Double getLat() {
return lat;
}
@Override
public void setLat(Double lat) {
this.lat = lat;
}
@Override
public Double getLon() {
return lon;
}
@Override
public void setLon(Double lon) {
this.lon = lon;
}
}
3. I have created a table in MYSQL called blc_geoproduct.
I have tried two tables (the two articles about extending entities seem to contradict themselves):
Table 1:
PRODUCT_ID BIGINT(20)
LAT Double
LON Double
Table 2:
GEOPRODUCT_ID BIGINT(20)
LAT Double
LON Double
PRODUCT_ID BIGINT(20)
It wasn't clear whether the foreign key constraint should be on a key other than the primary key (as is usually the case) or whether the primary key would also act at the foreign key.
4. I have amended persistence-core.xml:
<persistence-unit name="blPU" transaction-type="RESOURCE_LOCAL">
<non-jta-data-source>jdbc/web</non-jta-data-source>
<class>com.mycompany.catalog.entity.GeoProductImpl</class>
<exclude-unlisted-classes/>
</persistence-unit>
5. I have amended applicationContext-entity.xml:
<bean id="org.broadleafcommerce.core.catalog.domain.Product"
class="org.broadleafcommerce.core.catalog.domain.ProductImpl"
scope="prototype"/>
</beans>
The foreign key constraint gets created and from the admin console/create new product I am able to select type GeoProductImpl. I do however not see the two fields, though I don't know where they should appear in the console.
Any help would be appreciated.