Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Domain Model of Java Persistent with Hibernate

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JPwH's Caveat Emptor domain model (Fig 4.1) it uses 2 associations between Bid and Item classes to represent the successful bid must be from the Set of associated Bid instances. I'm not confortable with this design. For one thing, it is difficult to represent in UML that the associated successful Bid instance must be in the Set of all Bid instances associated with this Item.

I just want to know is there any better way to model this?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actaully it is what it is.

An Item will have a collection of bids made on it. One of them will be the highest winning Bid.

In the Item, I want to be able to call Bid getWinningBid(), or if I want to list out all the Bids, I want to be able to call List<Bid> getBids()

I could have Java code that loops through the List and gets the one with the highest bid, if the database doesn't store a winning_bid_id in the item table.

In the case of the example app CaveatEmptor, it is in the database and that is how they modeled the relationships and the object model. It is a nice design.

You also need to keep in mind that CaveatEmptor is a sample app to demonstrate all the different types of mapping that you might come accross in Hibernate, not a, this is the design you must follow.

So you can do whatever you want to do in your model or you mapping, Hibernate will be able to handle it.

Personally, I agree with the design in CaveatEmptor on the Item to Bids two relationships, in the object model and the database design. But this is my opinion.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic