Results 1 to 4 of 4

Thread: Hibernate Template question (default collection)

  1. #1

    Default Hibernate Template question (default collection)

    Hey,

    I am using a hibernate template to get at a collection of entities persisted in the database. I also create a custom collection class that i use to add additional behavior when objects are being added to the collection within hibernate. The findByNamedQuery method is returning an ArrayList. Is there anyway I can tell spring/hibernate to use my custom collection when building the collection.

    Some code to clarify

    Code:
    CorporateActionList entityList;
    		if(paramValues == null || paramValues.length == 0){
    			entityList = (CorporateActionList) hibernateTemplate.findByNamedQuery(namedQuery); //always returns arraylist
    What facility is available to inform spring/hibernate that I would like a collection of type CorporateActionList to be returned?

    Thanks.

    Roy

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    This isn't a Spring thing, this method will simply delegate to Query.list(). I'm not sure you'd be able to do what you want, but couldn't you put the results into your list after Hibernate has retrieved them?
    Last edited by karldmoore; Aug 27th, 2007 at 03:51 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #3

    Default

    I could but I want to add my own custom behavior to the add and remove method of list interface. I have to do something different to each entity that hibernate retrieves. It's going to be a pretty big list, and I don't want to have to loop thru it more than once.

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote Originally Posted by roykachouh View Post
    I could but I want to add my own custom behavior to the add and remove method of list interface. I have to do something different to each entity that hibernate retrieves. It's going to be a pretty big list, and I don't want to have to loop thru it more than once.
    Well I think you'll need to delve into the Hibernate source code. Hibernate has it's own Collection implementations so it can do clever things like lazy loading, I'm not sure what you can do about this.
    Last edited by karldmoore; Aug 27th, 2007 at 03:51 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •