I have two tables CAT and MICE
CAT table
(cat_id int primary key,
name varchar(16),
sex char(1),
weight double)
MICE
(mice_id int primary key,
name varchar(16),
eatenby int)
I want to perform an outer join using CAT, MICE.
Quote:
eatenby
field in MICE table is a foreign key that refernces CAT.cat_id. I don't want to use MiddleGen and XDoclet. I would like to
Quote:
create classes and hbm.xml files
corresponding to the given tables. Once this is done I would like to formulate the outer join query using CAT and MICE tables.
I am using the following code:Cat.javapackage net.sf.hibernate.examples.quickstart;
public class Cat {
private int id;
private String name;
private char sex;
private float weight;
public Cat() {
}
public int getId() {
return id;
}
private void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public float getWeight() {
return weight;
}
public void setWeight(float weight) {
this.weight = weight;
}
}
Mice.javapackage net.sf.hibernate.examples.quickstart;
public class Mice {
private int id;
private String name;
private Cat cat;
public Mice() {
}
public int getId() {
return id;
}
private void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Cat getCat() {
return cat;
}
public void setCat(Cat cat) {
this.cat = cat;
}
}
Mice.hbm.xml<hibernate-mapping>
<class name="net.sf.hibernate.examples.quickstart.Mice" table="MICE">
<id name="id" type="integer" unsaved-value="null" >
<column name="MICE_ID" sql-type="int" not-null="true"/>
<generator class="increment"/>
</id>
<property name="name">
<column name="NAME" length="16" not-null="true"/>
</property>
<many-to-one name="cat" class="net.sf.hibernate.examples.quickstart.Cat" column="cat_id"/>
</class>
</hibernate-mapping>
Cat.hbm.xml<hibernate-mapping>
<class name="net.sf.hibernate.examples.quickstart.Cat" table="CAT">
<id name="id" type="integer" unsaved-value="null" >
<column name="CAT_ID" sql-type="int" not-null="true"/>
<generator class="increment"/>
</id>
<property name="name">
<column name="NAME" length="16" not-null="true"/>
</property>
<property name="sex"/>
<property name="weight"/>
</class>
</hibernate-mapping>
After this in a file i am trying to call this query:
Query q1 = sess.createQuery(
"select cat.name " +
"from Cat as cat, Mice as mice " +
"outer join mice.cat as cat"
);
The code is comiling successfully. When i run the main file it gives
Quote:
Unable to execute query: net.sf.hibernate.JDBCException
and then the stack trace.[/quote]
I am unable to solve this problem. Plz suggest code changes required.....
Thanks......