The following ORM objects are defined in broadleaf: province, city, and area.

Source: Internet
Author: User

Key point: to define an ORM object in the broadleaf framework, you must first define an interface and then declare it in the persistence-unit configuration. If this parameter is not declared, the following error occurs: No persistent classes found for Query Class.

Iprovince:

import java.io.Serializable;import javax.annotation.Nonnull;public interface IProvince extends Serializable{        @Nonnull    public int getProv_Code();    @Nonnull    public String getProv_Name();}

Province:

import javax.persistence.CascadeType;import javax.persistence.EmbeddedId;import javax.persistence.Entity;import javax.persistence.FetchType;import javax.persistence.OneToMany;import javax.persistence.Table;import org.hibernate.annotations.Fetch;import org.hibernate.annotations.FetchMode;@Entity@Table(name = "PROVINCE")@SuppressWarnings("serial")public class Province implements IProvince,Serializable{@EmbeddedIdprivate ProvincePK prov_PK;@OneToMany(mappedBy = "province", cascade = CascadeType.MERGE, fetch = FetchType.LAZY)@Fetch(FetchMode.SUBSELECT)private Set<City> cities;public int getProv_Code() {return prov_PK.getProv_Code();}public String getProv_Name() {return prov_PK.getProv_Name();}public Set<City> getCities() {return cities;}public void setCities(Set<City> cities) {this.cities = cities;}public ProvincePK getProv_PK() {return prov_PK;}public void setProv_PK(ProvincePK prov_PK) {this.prov_PK = prov_PK;}}

Provincepk (joint primary key class ):

import java.io.Serializable;import javax.persistence.Embeddable;@Embeddable@SuppressWarnings("serial")public class ProvincePK implements Serializable{private int prov_Code;private String prov_Name;@Overridepublic boolean equals(Object obj) {if(obj instanceof ProvincePK){if(((ProvincePK) obj).getProv_Code() == this.getProv_Code()&& ((ProvincePK) obj).getProv_Name().equals(this.getProv_Name())){return true;}}return false;}@Overridepublic int hashCode() {return prov_Name.hashCode() + prov_Code;}public int getProv_Code() {return prov_Code;}public void setProv_Code(int prov_Code) {this.prov_Code = prov_Code;}public String getProv_Name() {return prov_Name;}public void setProv_Name(String prov_Name) {this.prov_Name = prov_Name;}}

 

Icity:

public interface ICity extends Serializable{        @Nonnull    public int getCity_Code();    @Nonnull    public String getCity_Name();}

City:

import org.hibernate.annotations.Fetch;import org.hibernate.annotations.FetchMode;@Entity@Table(name = "CITY")@SuppressWarnings("serial")public class City implements ICity,Serializable{@EmbeddedIdprivate CityPK city_PK;@OneToMany(mappedBy = "city", cascade = CascadeType.MERGE, fetch = FetchType.LAZY)@Fetch(FetchMode.SUBSELECT)private Set<Area> areas;@ManyToOne@JoinColumns({@JoinColumn(name = "prov_Code"),@JoinColumn(name = "prov_Name")})private Province province;public CityPK getCity_PK() {return city_PK;}public void setCity_PK(CityPK city_PK) {this.city_PK = city_PK;}public Set<Area> getAreas() {return areas;}public void setAreas(Set<Area> areas) {this.areas = areas;}public Province getProvince() {return province;}public void setProvince(Province province) {this.province = province;}@Overridepublic int getCity_Code() {return city_PK.getCity_Code();}@Overridepublic String getCity_Name() {return city_PK.getCity_Name();}}

 

Citypk:

@Embeddable@SuppressWarnings("serial")public class CityPK implements Serializable{private int city_Code;private String city_Name;@Overridepublic boolean equals(Object obj) {if(obj instanceof ProvincePK){if(((CityPK) obj).getCity_Code() == this.getCity_Code()&& ((CityPK) obj).getCity_Name().equals(this.getCity_Name())){return true;}}return false;}@Overridepublic int hashCode() {return city_Name.hashCode() + city_Code;}public int getCity_Code() {return city_Code;}public void setCity_Code(int city_Code) {this.city_Code = city_Code;}public String getCity_Name() {return city_Name;}public void setCity_Name(String city_Name) {this.city_Name = city_Name;}}

 

Iarea:

public interface IArea extends Serializable{        @Nonnull    public int getArea_Code();    @Nonnull    public String getArea_Name();}

 

Area:

@Entity@Table(name = "CITY_AREA")@SuppressWarnings("serial")public class Area implements IArea,Serializable{@EmbeddedIdprivate AreaPK area_PK;@ManyToOne@JoinColumns({@JoinColumn(name = "city_Code"),@JoinColumn(name = "city_Name")})private City city;public AreaPK getArea_PK() {return area_PK;}public void setArea_PK(AreaPK area_PK) {this.area_PK = area_PK;}public City getCity() {return city;}public void setCity(City city) {this.city = city;}@Overridepublic int getArea_Code() {return area_PK.getArea_Code();}@Overridepublic String getArea_Name() {return area_PK.getArea_Name();}}

 

Areapk:

@Embeddable@SuppressWarnings("serial")public class AreaPK implements Serializable{private int area_Code;private String area_Name;@Overridepublic boolean equals(Object obj) {if(obj instanceof ProvincePK){if(((AreaPK) obj).getArea_Code() == this.getArea_Code()&& ((AreaPK) obj).getArea_Name().equals(this.getArea_Name())){return true;}}return false;}@Overridepublic int hashCode() {return area_Name.hashCode() + area_Code;}public int getArea_Code() {return area_Code;}public void setArea_Code(int area_Code) {this.area_Code = area_Code;}public String getArea_Name() {return area_Name;}public void setArea_Name(String area_Name) {this.area_Name = area_Name;}}

 

The following ORM objects are defined in broadleaf: province, city, and area.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.