-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Hibernate in action design question
PostPosted: Fri Mar 03, 2006 4:01 pm 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
Hi folks,

I read the book Hibernate in action .. and in chapter 8, when they are working a real bid system example.. and refactoring..

they finish up with some data access object (DAO) which internally use Hibernate to get stuff from the underlying persistence store which is fine with me.

Where I start to question the design is when they have a method in the itemDAO class that returns the minimum and maximum bid for a given item (that is passed as a parameter)

here is the code:
BigDecimal currentMaxAmount = itemDAO.getMaxBidAmount(itemId);
BigDecimal currentMinAmount = itemDAO.getMinBidAmount(itemId);
Item item = itemDAO.getItemById(itemId);
User user = userDAO.getUserById(userId)
newBid = item.placeBid(user, newAmount,
currentMaxAmount, currentMinAmount);


I would have thought that the item class which has a placeBid() method should be responsible for knowing its own min / max bid. The way it is right now, it's up to the calling method to provide it to the placeBid.

Is there something I misunderstood here?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 4:10 pm 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
Also,


as long as I have an object in the persistance store, I can use the DAO to get it.. but what's the best way to persist a newly created object?

I mean I could Item item = itemDAO.getItem(id); if I have an item in the db..

but if I do

Item item = new Item();
// set item's properties

then using the architecture describe in the book, in the filter, the session would be close and therefor all persistance object would be saved. but since my newly created item is in transient state, it needs to be attached in some ways to the session. How should it be done according to the Hibernate in action book?

Thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 3:36 pm 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
Any thoughts on any of the above?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 4:03 pm 
Regular
Regular

Joined: Tue Mar 07, 2006 11:18 am
Posts: 54
Location: Berlin
martbl wrote:
Also,


as long as I have an object in the persistance store, I can use the DAO to get it.. but what's the best way to persist a newly created object?

I mean I could Item item = itemDAO.getItem(id); if I have an item in the db..

but if I do

Item item = new Item();
// set item's properties

then using the architecture describe in the book, in the filter, the session would be close and therefor all persistance object would be saved. but since my newly created item is in transient state, it needs to be attached in some ways to the session. How should it be done according to the Hibernate in action book?

Thanks again.


Hi martbl,
you could write a abstract BaseDAO class with owns a generic save(Object objectToSave) method. In this case just inherit each DAO from your base dao an associate your transient objects by calling the save method.


simon


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 4:18 pm 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
That's what I did.. but I thought there would be a more elegant way :)

Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.