wood burning stoves 2.0*
The moose likes Other Application Frameworks and the fly likes Collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Collections" Watch "Collections" New topic
Author

Collections

Bill Fly
Greenhorn

Joined: Mar 16, 2003
Posts: 12
If a PO class contains a collection of PO detail records, how would you use Spring to instantiate the detail objects to add to the collection? You would not know how many detail objects there were beforehand.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
I suppose you're looking for this?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
Originally posted by Lasse Koskela:
I suppose you're looking for this?


Lasse am not too clear about this. PO Detail records are determined at runtime for a PO. Do you think we can configure something like that in a config file? I mean specifying static dependencies in a config file makes sense to me. Am i missing something here?
Ryan Breidenbach
author
Greenhorn

Joined: Jan 06, 2004
Posts: 18
Karthik,

Can you explain a little bit more what you are looking for. Are you talking about retrieving a PO from the database?
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
Originally posted by Ryan Breidenbach:
Karthik,

Can you explain a little bit more what you are looking for. Are you talking about retrieving a PO from the database?


Ryan

Referring to Bill's originial post about retrieving PO details for a PO, the link to Spring docs shows how to initialize a list when the values are known up front. If the PO Lines are to be retreived from the database for a given PO, how would the declaration for classes PO, PoDetail look like in the Spring config file.
class PO{
List podetails;
}

I dont know but am just speculating, i hope bill wanted to know the same.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Ah. I missed the part about the contents of the list being dynamic... Sorry for the confusion.

I actually don't know any other way than to inject your bean with a DAO from which the object can ask for the list contents. I'd obviously be interested to hear about other ways of doing something like this...
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 335
    
    5
If I am understanding the original question correctly...

A PO and it's items are data objects. They describe some piece of business data (not logic). While I suppose that you could wire up a PO and its items in a Spring container, it doesn't make much sense. These items belong in the database.

The types of objects you wire up in Spring are service objects. This includes any service layer objects, DAOs, utility objects, etc. These object do something.

So, to answer your question, you wouldn't likely wire up a PO and its related line items in Spring. Those would be kept in a database and retrieve using JDBC or some ORM solution (like Hibernate).

If (let's say) you decide to use Hibernate. In that case you would wire up (in Spring) a Hibernate session factory and any DAO and service layer objects you need to retrieve the PO and its line items from the database. But the PO and its line items aren't wired...they're in the database.

Does that make sense?


Spring in Action - Unleash POJO power in your applications!
Modular Java - Discover the secret weapon to modularity on the Java platform!
XDoclet in Action - Your complete guide to code generation with XDoclet.
Bill Fly
Greenhorn

Joined: Mar 16, 2003
Posts: 12
Yes, pohdr and podtl are database tables. If I create a DAO class to retrieve them from the db tables and load them into a PO bean. The PO bean contains an ArrayList of PODtl objects; one for each row in the podtl table that has the same PO number as the PO header. Spring would instantiate the PO object before entering the DAO class, but how should entries in the ArrayList be created dynamically as rows are returned from the podtl table resultset?
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
I wouldn't have Spring create the PO header and detail beans. The DAO instead should be responsible for creating and saving PO records. Spring would create and wire up the DAO but not the data beans.
arnel nicolas
Ranch Hand

Joined: Dec 16, 2003
Posts: 149
i would suggest using Hibernate for that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collections