• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

embedded class question

 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys

could you please give me some hints on what is embedded class ?

i do not quite understand the use of the embedded in the hibernate annotation!

thank you
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, when we're doing Java class to database table mappings, we always talk about one table to one database table. That's the ideal. But sometimes, you have two classes that must map to ONE database table. But we only mark one class as the entity to be associated with the table. The second class, we say is embedded in the first class, and as such, the embedded class will map to the same database table as the embedded class.

On my website, I use an example where a Thing and a ThingDetail class, two separate classes in a Java domain model must map to a single database table, with the database table being named thing.

Mapping Multiple Java Classes to a Single Database Table with Hibernate and JPA Annotations



So, in this situation, I made the Thing the entity class that maps to the thing table.



But we also want the ThingDetail class to map to the same table, so we mark the ThingDetail class as being embeddable, namely, embeddable in the Thing class:



This is a simple example. In more complicated scenarios, compound primary keys are defined in a separate class, and those compound primary key classes become embeddable in the class for which they will act as a primary key. That's where you often see the embeddable annotation being used - in compound primary key classes.

Here's a little tutorial on compound primary keys, if you find yourself needing to use the Embeddable annotation in this type of scenario:

Tutorial on Using Hibernate and JPA Annotations to define Compound Primary Key Classes

-Cameron McKenzie
[ June 08, 2008: Message edited by: Cameron Wallace McKenzie ]
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic