-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Limitation:Temporary Table can't be null??
PostPosted: Sun Nov 15, 2009 2:31 pm 
Newbie

Joined: Thu Mar 05, 2009 3:56 pm
Posts: 10
Hi,

I am using the following SQL query in Restrictions.sqlRestriction argument for Criteria API upon whose execution, I get jdbc exception in Hibernate.

TABLE

Property (id,details)
Feature(property_id,desc)

property_id is a foreign key in Feature corresponding to Property

The query is:
Code:
Restrictions.sqlRestriction("{alias}.id in (select DISTINCT temp.tid from (select p.id as tid, COUNT(*) as freqfrom Property p, Feature f where p.id=f.property_id and (f.desc='Gym' or f.desc='Wifi')) as temp where temp.freq=2)");

My objective is to find all properties in Property Table which contain 'Gym' and 'Wifi' as features in Feature Table. So, I first create inner join of PropertyXFeature and select rows with desc field of the joined table matching 'Gym' or 'Wifi'. Now, property which will have both feature will appear twice in the Inner Joined Table. So for that, I select count(*) and later check if freq is 2.

Query works fine but throws exception when Inner Join Table contains no rows. In other words, when no property contains any of 'Gym' or 'Wifi' as feature, then I get an exception saying Column 'tid' can't be null. I guess this is probably because the temporary table created doesn't contain any rows/records and when I am performing another query(outer select) on it, it finds that tid field is not non-null any where and treats it as Primary key.

IS there any work around for such scenario? I need to use only Criteria API and any hql through Restriction only as I can add it to Criteria API. Can this scenario be achieved? I guess it should be as this is quite common scenario.

Looking for guidance.

Thanks,
Satyendra Mishra


Last edited by satyendra_411 on Tue Nov 17, 2009 5:16 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Hibernate Limitation:Temporary Table can't be null??
PostPosted: Tue Nov 17, 2009 5:15 am 
Newbie

Joined: Thu Mar 05, 2009 3:56 pm
Posts: 10
Sorry, I din't post the code and mapping.

Code:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "PROPERTY_TYPE", discriminatorType = DiscriminatorType.STRING)
public abstract class Property extends BaseEntity
{
   @CollectionOfElements
  private List<String>   features = new ArrayList<String>();
}


This results in two table
one is Property(id,features)
and other one is Property_Features(Property_Id,element)

For a property with 6 features, Property_Features table will have 6 rows with same Property_Id and different element corresponding to 6 different features.
Code:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.