Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can i model aggregate objects in hibernate?

 
Elhanan Maayan
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi..

we have an object which clearly does not have an entity on it's own, it's has few properties ,and a collections of chid objects, as well as methods to handle the child objects.

we have several entity objects which have many-to-one associtions which this type of object (a few with one-to-many even) but stilll it is not entity. so how do i model this in hibernate? do i still need to give equels/hash impementaion? placing it in it's own hbm file will force me to get it an identifer, but it's not ... an entitiy
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, Hibernate is an ORM tool, helping you map Objects in a Relational database to an object model. But it seems this aggregate object isn't relational. So, I don't think Hibernate will be able to map it, because there's nothing to map it to.

Figure out what the primary key is. Even if it's a composite key, made up of several fields, there must be some type of natural key. With a composite key, you can use Hibernate to map the object to the database.

The 'object' does get persisted at some point, doesn't it?

-Cameron McKenzie
 
Elhanan Maayan
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is no primary key for this thing, a good example for this type of info would an adress objects what with addtional child objects representing other relavent info.

this address objects would be part factory, person and other different entities.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without any way to uniquely identify the object, there is no way to persist it. And that only makes sense, because if you couldn't identify something and you persisted it, you could never retrieve it, because there is no unique identifier that could ever be used to obtain it.

So, it would appear that in this scenario, Hibernate won't be able to persist or manage your data or object. If you can figure out some way to uniquely identify it, then you're set. Otherwise, I guess it's just a generated runtime object.

Good luck!

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic