* table per class hierarchy -- just one table for entire class hierarchy
* table per subclass -- one table per subclass + a "super" table for the super-class
** defining feature is the one-to-one mapping between the super-table-rows and sub-table-rows
* table per concrete class -- one table per concrete (sub)class. No "super" table if the super class is abstract -- base scenario.
** defining feature is the union query
----
Q1: I have a table holding 2 types of rows. Half the rows are CashPayments, the others CreditCardPayments. I have 2 java bean classes CashPaymentBean.java and CreditCardPaymentBean.java. How do I configure hibernate mapping to map each CashPayment row to a CashPaymentBean and a CreditCardPayment row to a CreditCardPaymentBean?
Answer: This is about the 3 mapping strategies. Table per class hierarchy, per subclass, per concrete class.
For this case, need to use "table per class hierarchy".
key words for this specific question: "discriminator column",
<class name="Payment" table="PAYMENT"> <-- this is interface
...
<discriminator column="PAYMENT_TYPE" type="string"/>
<subclass name="CashPaymentBean" discriminator-value="CREDIT">
....
<subclass name="CreditCardPaymentBean" discriminator-value="CREDIT">
....
Q2: I have a lot of price data on IBM stock prices. I keep every price in the current month in main table, and older prices in history table. How do I configure hibernate to map a PriceBean.java to both tables, so I can load any price data into a PriceBean?
Answer: This question is also about one of the 3 mappings. It's "table per concrete class". This is the first time I look into the details about what the "table per concrete class" mean.
<class name="PriceBean">
<id name="id" type="long" column="PRICEBEAN_ID">
<generator class="sequence"/>
</id>
<property name="amount" column="AMOUNT"/>
...
<union-subclass name="PriceBeanCurrentMonth" table="MAIN">
<property name="..." column="..."/>
...
</union-subclass>
<union-subclass name="PriceBeanHistory" table="HISTORY">
...
</union-subclass>
</class>
On web service --
Q3: A web service client must authenticate with a web service, and then calls method1, then authenticate again, then calls method2. How can we avoid the 2nd authentication, which is unnecessary?
I have no idea about this.
Q4: how is driver registered with driver manager when you do a Class.forName(...)?
%A: I remember there's some magic in Class.forName(). Class.forName() dynamically loads the driver's class file into memory, which automatically registers it with the driver manager