-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Retrieve Child without Parent but with Parent ID
PostPosted: Sat Apr 04, 2009 5:51 am 
Newbie

Joined: Thu Apr 02, 2009 5:40 am
Posts: 6
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


Top
 Profile  
 
 Post subject: Does anybody have a clue regarding this matter ?
PostPosted: Fri Apr 10, 2009 1:53 pm 
Newbie

Joined: Thu Apr 02, 2009 5:40 am
Posts: 6
Does anybody have a clue regarding this matter ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 13, 2009 6:21 pm 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
You could try this instead

Code:
public class Person  {
   
   private Picture picture;
   private Integer pictureId;

   public Picture getPicture() {
      return picture;
   }
   public void setPicture(Picture picture) {
      this.picture = picture;
   }

  public Integer getPictureId() {
      return pictureId;
   }
   public void setPictureId(Integer pictureId) {
      this.pictureId = pictureId;
   }
}


This way you have a method that pulls back just the id and one that pulls back the full mapped class.

_________________
Please rate my replies as I need points for all of my questions also.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.