-->
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.  [ 1 post ] 
Author Message
 Post subject: Query problem with a constructor receiving associated entity
PostPosted: Sun Nov 18, 2007 10:42 pm 
Newbie

Joined: Sun Nov 18, 2007 9:35 pm
Posts: 1
I am using OneToOne between entity 'Product' and 'Photo'. One product can have no photos, or only one photo.

Mapping annotations:
Code:
public class Product{
   ...
   private Photo photo;
   
   public Product(String id, ... , Photo photo){
      ...
      this.photo=photo;
   }
   
   @OneToOne
   @JoinColumn(name="DEFAULT_PHOTO_ID")
   public Photo getPhoto() {
      return photo;
   }
   ...
}

public class Photo{
   ...
}

As above, there's a constructor in Product which allows me to pass a Photo into it.
I tried to list some columns of ALL products whether each of them has a photo or not, so I used the constructor like this:
Query code
Code:
Query query = entityManager.createQuery("select new Product(id,...,photo) from Product");
return query.getResultList();

But what I got is a list containing rows only from the products having photos.
It seems that the products having no photos are ignored...
So I checked the SQL and found a unexpected 'inner join' in it:
The generated SQL (show_sql=true):
Code:
select product0_.id as col_0_0_, ... product0_.DEFAULT_PHOTO_ID as col_8_0_ from PRODUCTS product0_ inner join PHOTOS photo1_ on product0_.DEFAULT_PHOTO_ID=photo1_.id

Now is the problem, maybe inner join is what Hibernate always does to a associated entity in constructor,
but is there a way I can use to list all entities with the customized contructor?

Thanks in advance.


Hibernate version:
3.2.1
Name and version of the database you are using:
Oracle 9i


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

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.