This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.

Ben Narendren

+ Follow
since Oct 01, 2009
Merit badge: grant badges
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ben Narendren

Thanks for your input and I apologize for the late reply. The deletion process I mentioned in not on a continuous block of id's. So after the deletion process there are mostly holes in the sequence. So if I reset the id to the 0 or 1, that will cause duplicate id's to be generated. That's why I need a better strategy to deal with this.
I have a table which gets a lot of records everyday and a lot of these records are deleted once a week by a batch job. I am running out of of id's very fast and I am thinking of a different strategy to generate id's. One idea I have is to reuse the deleted id's somehow. Any ideas out there?
Thanks Martin. I think this is what I was looking for.
I mean a connection level socket timeout which will be invoked if the physical connection is lost and the thread is hanging.

I am trying to put in a Socket time out on a Oracle JDBC connection. I googled it and didn't find much. I use DriverManager.getConnection(connectionString); to create connections. Anybody has any ideas how to do this? Any help is greatly appreciated.

Arnold and Jimmy, Thank you so much for your wonderful input.

I guess for now I can live with partial objects (bcos since both of you assured me that this is not poor design). DTO's are out of the question since there are DTOs and VOs involved at the external service level and at the view level correspondingly bcos of some restrictions we have and I don't want to add another layer of DTOs . So I guess if I have problems in the future with partial state, I'd go ahead and throw the IllegalStateException. That was an excellent idea btw, Arnold

I am creating a data/domain object - AvaiableHotel. I don't want to create an intermediate data transfer object to get the data back from the external service delegate.

Myl question here is: Is it good design that the first delegate returns a partial domain object (without the Amenities info) and the second delegate fills in the rest of the data (Amenities info) on that domain object ?
I have a HotelManager which will call two external services to create a AvailableHotel domain object.

1) HotelManager calls HotalAvailabilityDelegate
2) HotelAvailabilityDelegate connects to the external service, gets the data and creates a AvailableHotel domain object and returns it to HotelManager
3) HotelManager calls HotelAmenitiesDelegate
4) HotelAmenities delegate calls an external service and returns a HotelAmenitiesResponse
5) HotelAmenitiesResponse is used to fill in the rest of the data in AvailableHotel object by making a call like AvailableHote.populateAmenities(HotelAmenitiesResponse).

My problem is that the first time when HotelAvailabilityDelegate returns AvailableHotel, its a partial object in the sense that it doesn't have any Amenities info in it. Is this good design?

I thought of having HotelAvailabilityDelegate return a HotelAvailabilityReponse and creating the AvailableHotel object in the HotelManager itself. But the problem is I don't want to create an additonal object called HotelAvailabilityReponse just for data transfer.

Any thoughts anyone?
Mark, I was under the impression that what Aravind meant by 'Lazy loading' was the bringing of entities to the controller layer and fetching data from there. As far the association goes, I agree with you that we can't have two ends of an association placed in two different databases. Aravind, could you clarify if this is what you want?

Aravind Bhat wrote:What I need is a single service which connects to multiple data sources using separate transaction managers and to manage the transactions between them.

Aravind, I am not clear on something. Do you want multiple dbs to be part of the same transaction?

If yes, you don't need multiple transaction mangers. You need one JtaTransactionManager.
if No, you can use the same code I pasted in my post above and change the AOP settings to apply to the same service and specify which methods you want specific transaction managers to act on. But if you have a single method which accesses two different dbs under two transactional contexts, I suggest you separate these methods such that there is only one transactional context per method.

13 years ago are right .. I never did anything like that with annotations. I'll do some research on it and let you know if I find something. Anyway using regular XML I think we should be able to do this. Following is a section of code which I picked up from spring reference and tweaked to suit your purposes.

If you look at the code above , you'll see that there are two sets of services (service1Operations1 and service2Operations) and those two are seperately linked to two different TransactionManagers (txManager1 and txManager2)

13 years ago
The way to keep sessions open in the controller layer is by using OpenSessionInViewInterceptor provided by Spring. If you don't like what Spring is offering, you might have to write your own interceptor but the concept would be the same. I don't think that using TransactionProxyFactoryBean can help you with the session in view pattern. By the way, if you are using version 2.0 or up, its not a good idea to use TransactionProxyFactoryBean to configure transactions. You could use annotations or if you want to stick to xml , there is a much more sophisticated way to do this using AOP.
13 years ago
Since the CAR table has the PERSON_ID column (I find this a little unusual though), I am assuming the Car object is pointing to a Person object. In that case your Car class should be

and your car mapping should be

If you truly really want a bidirectional relationship and wish a pointer from person to car, the person mapping should be

I believe what you need might be something like this

from Ability as ability
inner join fetch ability.abilityType

This way you don't have to deal with object arrays.

If you don't want to fetch the abilityType , you need something like

from Ability as ability
inner join ability.abilityType

Please take a look at this java world article on EJB facades over Spring Business services

This piece of code which you will find in the article is an example of where getBean() is called instead of DI

13 years ago
Hibernate is a very good bet for your situation. The simple answer to your question is to apply the Data Mapper pattern (refer Patterns of EAA by Fowler). But instead of reinventing the wheel, you might as well use Hibernate which has a very good implementation of Data Mapper. Hibernate supports

1) Lazy Loading
2) You can specify which objects you want to eager fetch
3) If these objects have a child hierarchy you can setup the depth to which you want to fetch
4) In addition, Hibernate gives you a lot of out of the box functionality which you will need implement a DAO pattern effectively