Subtypes and association problems


The problem of subtypes
Let us imagine a given situation:
User class is connected with BillingDetails. During performing on class object BillingDetails an instance of one of the subclasses of this class can be ascribed. Therefore the User object will actually refer to an object from different class than BillingDetails. It is a quite common way of conduct as far as an object programming is concerned. We would like to have a similar opportunity while dealing with databases, however, it is not possible that any field in a table (here: a foreign key) may refer to some fields in a few different tables. That is why while saving similar situations in a database we have to choose another solution.




The problem of association
The following situation can happen in Java: While mapping this kind of situation to a database we have to bear in mind that we cannot directly save many-to-many paradigm and we have to create an intermediate table.
Hibernate (like other similar technologies, e.g. JDO, Entity Beans) meets our expectations. Hibernate becomes an additional layer in our application, a bridge between the logic of an application and a database (object/relational mapping). It enables us to define objects storing data ( as typical Java class), which can be used in our application and which are mapped to a database in a definite way. Hibernate provides us also with its own query language, structurally very similar to SQL. Both these facts make an application using Hibernate more portable.