Search code examples
javahibernatehibernate-mapping

Hibernate Master-SubDetails Mapping


I'd like to explore Hibernate and used it in my project instead of JDBC. My table design is highly normalized.

Suppose, I have this use case: Each insurance applied by a customer has one associated rateplan. Usually, in RDBMS this is implemented using two tables like below.

Table Insurance:
    id long;
    accountHolder varchar;
    ratePlanId int;  -->Rate Plan Id is Foreign Key to the RatePlanTable

Table RatePlan:
    ratePlanId int;
    ratePlanDesc varchar;
    discountRate double;

Now, my question is..does this qualify as a onetomany relationship?

Most of the examples that I am seeing on the net regarding onetomany, involves some sort of collections (e.g An Order has a list of products). And when represented in class is translated below, which I think is really a one to many case?

public class Order{
    private List products;
}

But how about my case? I don't think that it is a onetomany or I am just mislead by the examples?

How can I do a hbm mapping for my two classes? In my case, I would create two class to represent the two tables, but I am not sure how the hbm.xml would look like for the two class.


Solution

  • Yes, it is a one to many relationship, in that one rate plan is associated with many insurance policies. In entity traversal, when you would go from the Policy, you would get one Plan object, and conversely, from a Plan object, you would get a list of Policy objects.