Labels

_fuxi (75) _IV (146) _misc (5) {610610 (30) algo (1) automatedTrading (8) banking/economy (3) book (14) c++misc (125) c++real (15) c++STL/java_container (7) cppTemplate (1) db (13) DB_tuning (4) deepUnder (1) dotnet (69) eTip (17) excelVBA (12) finance+sys (34) financeMisc (24) financeRisk (2) financeTechMisc (4) financeVol (21) finmath (17) fixedIncome (25) forex (16) IDE (24) invest (1) java (43) latency (4) LinearAlgebra (3) math (30) matlab (24) memoryMgmt (11) metaPrograming (2) MOM (15) msfm (1) murex (4) nofx (11) nosql (3) OO_Design (1) original_content (4) scriptUnixAutosys (19) SOA (7) socket/stream (15) sticky (1) subquery+join (2) swing (32) sybase (6) tech_orphan (12) tech+fin_career (30) telco (11) thread (21) timeSaver (13) tune (10) US_imm (2) US_misc (2) windoz (20) z_algo+dataStructure (4) z_arch (2) z_c#GUI (30) z_career (10) z_career]US^Asia (2) z_careerBig20 (1) z_careerFinanceTech (11) z_FIX (6) z_forex (31) z_hib (2) z_ikm (7) z_inMemDB (3) z_j2ee (10) z_oq (14) z_php (1) z_py (26) z_quant (4) z_skillist (3) z_spr (5)

Saturday, January 15, 2011

2 Hibernate IV questions

My hasty summary, to be validated --

* 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.

On JDBC --

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