Hibernate version: Hibernate 3.0
I want to sometimes populate objects and their associations from a view, but also sometimes populate them "normally", allowing Hibernate to generate the SQL and joins.
I have a standard parent-child, one-to-many relationship. For existing objects in the database, the normal Hibernate mapping suffices.
But for objects that don't yet exist, I have a view that provides "potential" objects. I would like to populate from the views, do some processing to complete the object graph, then save the objects into the database, after some processing.
How can I get Hibernate to populate from the views?
In more detail: A Questionnaire object has a (1-M) association to set of Questions, each of which has a (1-M) association to a Set of Answers. No problem here, the normal Hibernate populating works fine.
Each Questionnaire also has a (1-M) association to a Set of AnsweredQuestionnaire, which has a (1-M) association to a set of AnsweredQuestions.
Each AnsweredQuestion has a (1-1) association to a Question and a (1-1) association to an Answer. (It's a M-M table, essentially.)
It's the AnsweredQuestionnaire and AnsweredQuestions I want to populate from the view; this will provide as-yet-not-existing-in-the- database AnsweredQuestion object, and its associated Set of as-yet-not-existing-in-the-database AnsweredQuestions.
After setting the (1-1) link to each AnsweredQuestion's answer, I'll cascade save the AnsweredQuestionnaire to the database.
How do I write a Hibernate mapping that populates an AnsweredQuestionnaire and its Set of AnsweredQuestions from views?
Thanks.
|