• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Simple Hibernate Example with Embedded Class

 
Ranch Hand
Posts: 42
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
It's a tiny ad. At least, that's what she said.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic