concept Bid in category hibernate

appears as: Bid
Java Persistence with Hibernate, Second Edition

This is an excerpt from Manning's book Java Persistence with Hibernate, Second Edition.

In this book, we’ll think of the problems of data storage and sharing in the context of an object-oriented application that uses a domain model. Instead of directly working with the rows and columns of a java.sql.ResultSet, the business logic of an application interacts with the application-specific object-oriented domain model. If the SQL database schema of an online auction system has ITEM and BID tables, for example, the Java application defines Item and Bid classes. Instead of reading and writing the value of a particular row and column with the ResultSet API, the application loads and stores instances of Item and Bid classes.

At runtime, the application therefore operates with instances of these classes. Each instance of a Bid has a reference to an auction Item, and each Item may have a collection of references to Bid instances. The business logic isn’t executed in the database (as an SQL stored procedure); it’s implemented in Java and executed in the application tier. This allows business logic to use sophisticated object-oriented concepts such as inheritance and polymorphism. For example, we could use well-known design patterns such as Strategy, Mediator, and Composite (see Design Patterns: Elements of Reusable Object-Oriented Software [Gamma, 1995]), all of which depend on polymorphic method calls.

The relationship we’ll explore in the following sections is always the same, between the Item and Bid entity classes, as shown in figure 7.13. The association from Bid to Item is a many-to-one association. Later you’ll make this association bidirectional, so the inverse association from Item to Bid will be one-to-many.

Figure 7.13. Relationship between Item and Bid

At the beginning of this chapter, we had a list of reasons a mapping of the collection Item#images was a good idea. Let’s do the same for the collection Item#bids. This collection would implement the one-to-many association between Item and Bid entity classes. If you create and map this collection property, you get the following:

Figure 7.15. Bidirectional association between Item and Bid