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