-->
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: COmposite-Id and Usage of SUBSELECT queries
PostPosted: Sat Sep 27, 2008 5:46 pm 
Newbie

Joined: Sat Sep 27, 2008 3:05 pm
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:2

Mapping documents:
1) BUNDLE_PRODUCT is a table that has the BUNDLE_ID (Foreign key from BUNDLE table) and PRODUCT_ID (Foreign key from PRODUCT table)
2) BUNDLE_ID and PRODUCT_ID has many-to-many relation with each other
3) ONE SCENARIO -> I need to fetch one BUNDLE_ID for a given set of PRODUCT_ID s.
4) SECOND SCENARIO -> to get the PRODUCT_ID s for a given single BUNDLE_ID.

I am not sure if the below mapping is right. I have created the BundleProduct class with id and the BundleProductPK class that carries the composite ids bundleId and productId

<class
name="com.......retail.BundleProduct"
table="BUNDLE_PRODUCT"
>

<composite-id name="id" class="com....retail.BundleProductPK">
<key-property name="bundleId" column = "BUNDLE_ID" />
<key-property name="productId" column = "PRODUCT_ID" />
</composite-id>
</class>

Code between sessionFactory.openSession() and session.close():
Session session = null;
Integer bundleID = Integer.valueOf("0");
try {
SessionFactory factory = getHibernateTemplate().getSessionFactory;
session = factory.openSession();
Query query = session.createQuery("select bp.id.bundleId from BundleProduct bp where bp.id.productId = 12 and bp.id.bundleId in (select bp.id.bundleId from bp where bp.id.productId = 6)");
Iterator iter = query.iterator();
while(iter.hasNext()){
bundleID = (Integer)iter.next();
}
}catch (Exception e){
e.printStackTrace();
}

Full stack trace of any exception that occurs:
net.sf.hibernate.QueryException: in expected: bp

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

The generated SQL (show_sql=true):
the same sql in the code with the above excetion in the console

Debug level Hibernate log excerpt:
No logging

As there is a critical situation for this . I need some help on hbm and the mapping that need to be made in this case so that i can use it. Also i need to know how to form a HQl query in this case using a Query object. Usage of subselect queries.



Read this: http://hibernate.org/42.html

_________________
- Chanthos


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.