• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic question about Hibernate

 
Sanath Kruttiventi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to understand the design of Hibernate at the core level, got one doubt, please provide comments, may be corrections in my thought of course.

If my organization is well 'package established', it means that all my domain objects have been well built with proper encapsulation and highly cohesive in nature and 'package'd well with beautiful hierarchies.
Thus, any further software/application design may use these templates (classes) to build its own design, may be messaging, may be database and may be something big or small, whatever app my company needs.
If Hibernate has to use these structures, it seems an issue there because any relations has to be defined inside these classes (like Set for multiplicity).
So, in such case of my company, for hibernate I have to extend all required classes to build H_classes for each, which can accommodate its specific collections as per what database needs to hold relations.
So, this means, Hibernate cannot generate relation objects dynamically as needed ?
To explain what I think, this below is example.
As of the design, if Course(1) is related to Student(N), hibernate needs a Set of Students to be defined inside Course class, not sure I am thinking in wrong way, here we are actually changing the behavior of Course with respect to database, means a design issue ? it means, if something new comes up for Course, like many Colleges teaches the Course, we add Set of Colleges to Course class again ? thus keep on updating Course class as needed ?
Instead, if once mapping is defined on the relations, can't hibernate generate these object dependents dynamically so that no matter any number of relations Course has, Course will just remain with its details only instead of these specific Sets inside. Now, can any ORM generate dependent relation classes like Course_Student, Course_College and its objects and populate associations internally as per database rows? will this be more dynamic ? In this case, I can just use my well defined domain objects directly to ORM without these internal collection mappings since during runtime my ORM generates and maps relations with base objects ?
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the CodeRanch!
for hibernate I have to extend all required classes to build H_classes for each, which can accommodate its specific collections as per what database needs to hold relations.

If the existing domain model is designed properly (as you explained), I don't think you need any (if not few) changes to your domain model. It's ORM so you map Objects (with its dependencies) to relational model in the OO world.

it means, if something new comes up for Course, like many Colleges teaches the Course, we add Set of Colleges to Course class again ? thus keep on updating Course class as needed ?

Yes, that is why the initial design is very important.

Instead, if once mapping is defined on the relations, can't hibernate generate these object dependents dynamically so that no matter any number of relations Course has, Course will just remain with its details only instead of these specific Sets inside.

Even if it could where is it going to store those data and how the code accesses them?
 
Sanath Kruttiventi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response, here below is what I think an ORM may provide. This type may not work at all, just a thought.
Any initial design cannot presume what new business requirements can come up in future to accomodate the relations,
like if any new object to me mapped or mapping to be removed as well.
This is more to be focussed on realizing mappings dynamically without changing / replicating well defined objects,


(1) Define just plain POJOs representing their base tables without any collections inside(Course and Class for example)
This keeps my objects totally independent of relations and future changes of these relations as well (add new and remove existing).
(2) Just define these dependencies in mapping files only.
Typically, this should have what keys from both tables represents the mapping table rows, and the name of mapping table.
(3) Just using above details, I think ORM may be able to (just to propose this feature) build the logic to create
classes dynamically basing on meta data extracted from mapping table, create objects and populate "required" records basing on user code.
For say, from such capability, if I try to extract my object basing on query like COURSE_ID=1001, I would get the Course object.
since mapping was defined using mapping DB table, there must be some architecture to extract dependents and attach it to the object when user asks for.
Something like, Set course_students = ORMUtils.getDependentSet(course_object, "course_student") //using object and key defined for mapping table in xml.
above one is more like a query from DB end, like select * from course_student where course_id=<<course_object.course_id here>>
Just here I am thinking, whether any struts DynaActionForm like defaults can be provided from mapping which can make these dependent objects.

Thanks again.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic