This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections

 
Bill Fly
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose you're looking for this?
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 363
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bill Fly
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i would suggest using Hibernate for that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic