This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Blog around the Campfire and the fly likes Simple Hibernate Example with Embedded Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Other » Blog around the Campfire
Bookmark "Simple Hibernate Example with Embedded Class" Watch "Simple Hibernate Example with Embedded Class" New topic
Author

Simple Hibernate Example with Embedded Class

Christopher Rygaard
Ranch Hand

Joined: Feb 22, 2014
Posts: 42
    
    3
Simple Embedded Class Example

This is the simplest stand-alone example of an embedded class in Hibernate that I could cook up.

This example shows how one class (MyEmbedded) is 'contained' in two other classes (ComplicatedData1 and ComplicatedData2). The trick is the Embeddable annotation on the MyEmbedded class, and the Embedded annotation on the instances of MyEmbedded.

When using embedded classes, it seems like good practice to provide a more complete column name for the instance variables in the embedded class. This will reduce the probability of a naming collision when it is embedded in another class. This is pointed out in the code comments.

Notice: This is provided with no warranty whatsoever. Use at your own risk.

This is the embedded class:

This is the first class that will have an instance of the embedded class:

This is the second class that will have an instance of the embedded class:

This is an example showing how it is used.
 
jQuery in Action, 2nd edition
 
subject: Simple Hibernate Example with Embedded Class
 
Similar Threads
Simple Hibernate Container Example
Simple Hibernate Example with Inner Classes
Simple Hibernate Cascade Save Example
One class whose instances are contained in multiple other classes.
Simple Hibernate POJO example