ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Farsi, Reza" <Reza.Fa...@SUNGARD.DE>
Subject Avoiding selects and other problems with complex objects / Hibernate
Date Tue, 20 Sep 2005 12:36:57 GMT
I don't know, if I can describe my queotion clealy, but I try it.

Following scenario:
There are two objects Fund and Instrument. Instrument hat one composite
object called Interest. Fund does not reference any other obejct.
Instrument reference only Interest.
There is also an obejct called BookingRequest that references a Fund and
an Instrument.

Database modeling is as followes
create table fund
	id	int not null auto_increment primary key, 
	name 	varchar(50) not null,

create table instrument (
	id int not null auto_increment primary key, 
	name varchar(12) not null unique,

create table interest (
	instrument_id int not null auto_increment primary key,
	name varchar(12) not null,
	constraint interest_fk_01 foreign key (instrument_id) references

create table booking_request (
	id int not null auto_increment primary key, 
	fund_id int not null, 
	instrument_id int not null, 
	transaction_date date, 

	constraint booking_request_fk_01 foreign key (fund_id)
references dd_fondsstamm (id), 
	constraint booking_request_fk_02 foreign key (instrument_id)
references ip_ins_instrument (id)

And on the Java sind:
public class Instrument {
	// parameters skipped
	private Interest interest;
	// Getters and setters

public class BookingRequest {
	// parameters skipped
	private Fund fund;
	private Instrument instrument;
	// Getters and setters

Fund and instrument have their own mapping files. By selecting
instrument objects the problem of N+1-select is solved.

Now assume that there is an BookingRequest DAO that supports a method
"getBookingRequestByFund(int fundId)".

By definition of mapping for BookingRequest the mapping of Fund and
Instrument attributes are fetched using Select statements specified in
Fund.xml respectivly Instrument.xml.
That means, that fetching a BookingRequest causes three select calls.
How can I get BookingRequest objects by only one select.

A solution like mapping of referenced Fund within resultMap of the
BookingRequest makes the mapping complex and the maintainace more

I know that Hibernate takes care of the object relations and optimizes
the select. Is there any mechanism in iBATIS provide this problem

Thanks in advance and frindly regards,

View raw message