One class whose instances are contained in multiple other classes.

Christopher Rygaard

Ranch Hand

Posts: 42

3

posted 2 years ago

Hi all!

Can somebody point me to an example showing how I can have instances of one class contained in different kinds of container classes in Hibernate? I think my question is "What annotation do I put onto the instance of the contained class so that it can be contained by different classes of containers?".

My end users will be entering different kinds of engineering information, and I want to attach some explanation to each chunk of data (the various kinds of data chunks are represented by different classes). I have created an "ExplanatoryNotes" class to handle the explanations. I want to attach ExplanatoryNotes instances to the various data chunks, in different classes.

If somebody could point me to an example of how to do this, or if somebody could tell me how to get my example working, I would be most grateful.

P.S. I'm an experienced Java programmer, and I have some SQL experience, also. However, I am a rank beginner with Hibernate. I have built several Hibernate examples, including various kinds of relations (including a full-on tree), so I have some understanding of some of the basic concepts in Hibernate. Having said that, it is entirely possible that I am demonstrating a misunderstanding of Hibernate concepts: If so, please set me straight.

Thanks ahead of time for any input!

This is a distillation of my ExplanatoryNotes class:

This is the first (simplified) example of how I want to use ExplanatoryNotes:

And this is a second (simplified) example of how I want to use ExplanatoryNotes: