Hi,
I have created a simple one-to-one mapping and after issuing the correct hibernate-generated SQL involving a JOIN, it starts issuing single selects for each and every ID in the table. I have done the same thing with other classes, the only difference being that the identifying column names are different in this case, and it worked fine (i.e. only the JOIN query was executed). My mapping code is below, along with the two classes, and the "findAll" query.
Any help would be hugely appreciated. I have spent much time on this, and tried every permutation of attributes that made sense to me, to no avail.
Thanks.
Lee.
Hibernate version: 3.1.1
Database: MySQL 5
public class Model {
private String modelCode;
private Integer year;
private String productLine;
private String fullName;
private ModelCategory category;
public Model() {
super();
}
public boolean isHonda() {
return productLine.equals("A");
}
public String getFullName() {
return fullName;
}
private void setFullName(String fullName) {
this.fullName = fullName;
}
public String getModelCode() {
return modelCode;
}
private void setModelCode(String modelCode) {
this.modelCode = modelCode;
}
private String getProductLine() {
return productLine;
}
private void setProductLine(String productLine) {
this.productLine = productLine;
}
public String getSimpleName() {
return category.getName();
}
public Integer getYear() {
return year;
}
private void setYear(Integer year) {
this.year = year;
}
public ModelCategory getCategory() {
return category;
}
public void setCategory(ModelCategory category) {
this.category = category;
}
}
public class ModelCategory {
private String modelCd;
private String name;
public ModelCategory() {
super();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getModelCd() {
return modelCd;
}
public void setModelCd(String modelCd) {
this.modelCd = modelCd;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Model" table="MODEL_S" dynamic-update="true" dynamic-insert="false" lazy="false">
<id name="modelCode" column="MODEL_CDE"/>
<property name="year" column="MODEL_YEAR" not-null="true"/>
<property name="productLine" column="PROD_LINE" not-null="true"/>
<property name="fullName" column="MODEL_NAME" not-null="true"/>
<one-to-one name="category" lazy="false"/>
</class>
<class name="ModelCategory" table="MDLCTG_S">
<id name="modelCd" column="MDLCDE"/>
<property name="name" column="CTGNM"/>
</class>
</hibernate-mapping>
|