-->
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: Generic Hibernate Fetching
PostPosted: Thu Mar 05, 2009 9:17 am 
Beginner
Beginner

Joined: Wed Aug 22, 2007 5:53 am
Posts: 38
public class Item {
private String name;
private Set categories = new HashSet();
private Set bids = new HashSet();
private Bid successfulBid;
...
}
----------------------------------------------------
public class Bid {
...
private Item item;
...
}

-----------------------------------------------------
public class User {
private Address shippingAddress;
private Set billingDetails;
..
}

-----------------------------------------------------
public class Category {
private String name;
private Category parentCategory;
private Set childCategories = new HashSet();
private Set items = new HashSet();
..
}
-----------------------------------------------------



Considering Item, Bid, User, Category:
The usecase requirement is as follows:

USECASE 1 : Require item.successfulBid, item.categories.parentCategory
USECASE 2 : Require item.categories.childCategories
USECASE 3 : Require item.bid , item.user.shippingAddress, item.user.billingDetails
USECASE 4 : Require complete item (including it's associations and collections populated)

If i write a generic DAO method which will accept which all populated associations and collections of Item should be written...
Based on this input (and dynamic eager fetching), i will create a dynamic HQL which will fetch only the required data.


Item getItem(String itemId, Vector criteria){
//generate dynamic HQL using this criteria elements in fetch clause
}


So in:
UseCase1:
Vector criteria = new Vector(0,1);
criteria.add("item.successfulBid");
criteria.add("item.categories.parentCategory");
Item item = getItem(criteria);

UseCase2:
Vector criteria = new Vector(0,1);
criteria.add("item.categories.childCategories");
Item item = getItem(criteria);

UseCase3:
Vector criteria = new Vector(0,1);
criteria.add("item.bid");
criteria.add("item.user.shippingAddress");
criteria.add("item.user.billingDetails");
Item item = getItem(criteria);

UseCase4:
Vector criteria = new Vector(0,1);
criteria.add("*");
Item item = getItem(criteria);

Is this a good idea..? Comments plz..


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 05, 2009 10:25 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
If you call your Vector Criteria, why don't you use Criteria API then? If you don't have access to session at that part of your program, you could use a DetachedCriteria:
Code:
DetachedCriteria.forClass(Item .class).setFetchMode("successfulBid", FetchMode.JOIN).setFetchMode("categories ", FetchMode.JOIN).createCriteria("categories", "cat").setFetchMode("cat.parentCategory", FetchMode.JOIN);
....

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 06, 2009 2:50 am 
Beginner
Beginner

Joined: Wed Aug 22, 2007 5:53 am
Posts: 38
Yes.. either HQL fetch query or Criteria API..
but my main query was, Am i on right track.. Is this approach good as i have not seen this approach yet ..


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.