Hibernate version:3.3.1.GA
Hello,
I have a classical relation Parent - Child, let's say for example Person - Picture and 2 problems related to this situation :).
Code:
public class Person {
private Picture picture;
public Picture getPicture() {
return picture;
}
public void setPicture(Picture picture) {
this.picture = picture;
}
}
public class Picture {
private int pictureId;
byte[] picture;
public int getPictureId() {
return pictureId;
}
public void setPictureId(int pictureId) {
this.pictureId = pictureId;
}
}
My mappings are:
Code:
<class name="entity.Person" entity-name="Person" table="person">
<id name="personId" column="PERSONID">
<generator class="native" />
</id>
<many-to-one name="picture" entity-name="Picture" column="PICTUREID" unique="true" not-found="ignore"/>
</class>
<class name="Picture" entity-name="Picture" table="picture">
<id name="pictureId" column="PICTUREID">
<generator class="native" />
</id>
<property name="picture" column="PICTURE" />
</class>
Problem no 1:
Retrieve a Person with it's picture Id, but without Hibernate to make an inner join behind an retrive the picture with it's content etc...
So when I'll call person.getPicture().getPictureId() the getter to return the pictureid form PERSON's TABLE.
Problem no 2:
Also I want to search on Person after it's pictureId in hql like this:
from Person as p where p.picture.pictureId = 10;
I want the above HQL to be transformed in this SQL:
Code:
select * from PERSON as p where p.PICTUREID = 10
and NOT in:
select * from PERSON as p inner join PICTURE as pi where p.PICTUREID = pi.PICTUREID where pi.PICTUREID = 10;
Thanks,
Dan