-->
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: many-to-one fetches only not nullables ? hibernate 2.1
PostPosted: Wed Dec 07, 2005 2:33 pm 
Newbie

Joined: Tue Nov 02, 2004 5:37 pm
Posts: 17
Greetings to all,

I need your help in the following (using hibernate 2.1)

i have an object Product that has the following relation to another object :
<many-to-one name="producttheme" class="net.db.ProductTheme" column="product_theme_id" />

I have created a simplified class ProductLight that has a number of constructors.

public ProductLight(Long id,String titlegr, String titleen, String image, float price, float discount, int active, net.db.ProductType producttype, net.db.ProductTheme producttheme,String code ) {
this.id=id;
this.titlegr = titlegr;
this.titleen = titleen;
this.image = image;
this.price = price;
this.discount = discount;
this.active = active;
this.producttype = producttype;
this.producttheme = producttheme;
this.code = code;
}

When i query it fetches only the products that the product_theme_id is not null. How can i overcome this problem, in order to fetch null product_themes as well ?

select new net.eshop.db.ProductLight(p.id,p.titlegr,p.titleen,p.image,
p.price,p.discount,p.active,p.producttype,p.producttheme,p.code)
from Product as p

Thanks in advance

L


Top
 Profile  
 
 Post subject: Re: many-to-one fetches only not nullables ? hibernate 2.1
PostPosted: Wed Dec 07, 2005 2:54 pm 
Regular
Regular

Joined: Thu Aug 19, 2004 9:28 am
Posts: 63
sygram wrote:
Greetings to all,

I need your help in the following (using hibernate 2.1)

i have an object Product that has the following relation to another object :
<many-to-one name="producttheme" class="net.db.ProductTheme" column="product_theme_id" />

I have created a simplified class ProductLight that has a number of constructors.

public ProductLight(Long id,String titlegr, String titleen, String image, float price, float discount, int active, net.db.ProductType producttype, net.db.ProductTheme producttheme,String code ) {
this.id=id;
this.titlegr = titlegr;
this.titleen = titleen;
this.image = image;
this.price = price;
this.discount = discount;
this.active = active;
this.producttype = producttype;
this.producttheme = producttheme;
this.code = code;
}

When i query it fetches only the products that the product_theme_id is not null. How can i overcome this problem, in order to fetch null product_themes as well ?

select new net.eshop.db.ProductLight(p.id,p.titlegr,p.titleen,p.image,
p.price,p.discount,p.active,p.producttype,p.producttheme,p.code)
from Product as p

Thanks in advance

L


Have you tried specifying an outer join in your from clause, like this

select new net.eshop.db.ProductLight(p.id,p.titlegr,p.titleen,p.image,
p.price,p.discount,p.active,p.producttype,p.producttheme,p.code)
from Product as p left join p.producttheme ?

Cheers (I need credits so, if this helped you in anyway, give me some :) )


Top
 Profile  
 
 Post subject: thanks
PostPosted: Wed Dec 07, 2005 3:34 pm 
Newbie

Joined: Tue Nov 02, 2004 5:37 pm
Posts: 17
so simple and worked like a charm ;)

Thanks


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.