Need Your Help: Hibernate Inheritance Mapping..


Web tier: servlets, JSP, Web frameworks: Need Your Help: Hibernate Inheritance Mapping..

  1. Need Your Help: Hibernate Inheritance Mapping.. (1 messages)

    Hi All, This question is regardig 'Table per class hierarchy' mapping. I have a class A. I have a class B extends A. I have only one table (say T1) in the database for both A and B. class A { private String a1; private String a2; private String a3; // Setters and Getters here } class B extends A { private String b1; // Setters and Getters here } Table T1 has columns as follows: A1_COL VARCHAR2(10) PK A2_COL VARCHAR2(10) A3_COL VARCHAR2(10) B1_COL VARCHAR2(10) Suppose T1 has a row like this: 100 200 300 null SEQ_A1 ............ ............ Using Hibernate program I need to do the following task: 1) Retrieve the row based on primary key (100). 2) Set "B1_COL" value to 500 instead of null. 3) Update the database with new values. I mean the above program should result in the following row in Database. 100 200 300 500 Appreciate your quick help. This might be simple question, but i am new to Hibernate, so kindly help me. Thanks n Have a nice day,
  2. An attempt: Thinking in Objects[ Go to top ]

    Hi, I dont know anything about Hibernate, but I have some exposure to OR Mapping. So here's is an attempt to answer your query: With OR Mapping tools, one should stop worrying about the tables and think in terms of only the classes or objects. ( Isn't that the very reason OR Mapping tools are there! ) Now your query has actually become this: Lets take Animal as A and Dog as B. Car class has an extra attribute called 'barking'. You have persisted an instance of Animal and now you want to 'update' it with its barking sound. But how can you ask an Animal to bark unless it is a dog??! So thinking in objects, what you would want to do is to get the dog from data store( yes the datastore has only a Animal, but a dog IS-A animal, isn't it? ) and update the dog with the barking attribute. With the polymorphism support of hibernate, you should be able to do something like this: B bInst = EntityManager.load(B.class, 100 ); //polymorphic bInst.setB1(500); EntityManager.update(bInst); I saw something in hibernate forums about getting this to work by setting a polymorphism option in the mapping. Can somebody with hibernate knowledge give a useful solution to this?