Submitted by sneha on Wed, 11/13/2013 - 03:18
When mapping two entities, we annotate both classes as @Entity and the mapping type is specified as @OneToOne, @OneToMany, @ManyToOne or @ManyToMany over the declaration of one entity class in the other entity class. In One-To-One mapping, we refer to one entity from another and mark the reference variable as @OneToOne.
Submitted by sneha on Wed, 11/13/2013 - 03:12
Consider a user class with an embedded list of addresses, or a company class with a list of employee details. By default, when you load the embedding class (user or company) using session.get, the embedded collection (addresses or employee details) is not actually retrieved from database, but only the top level fields are retrieved. The collection list is retrieved when you call the getter for that embedded collection. This is called lazy initialization fetch in hibernate. The alternative is called eager initialization fetch.
Submitted by sneha on Wed, 11/13/2013 - 01:00
There might be situations where you would want to modify the attributes of the embedded class (eg. Address) within an embedding class (eg. User), for instance, changing the database column name for a field. You can do this within the embedded class itself. But what if you don’t have access to the embedded class or if you want different behavior for two different instances of the embedded class; you will have to override the embedded class behavior in the embedding class.
Submitted by sneha on Wed, 11/13/2013 - 00:02
An entity class can refer to other entity classes or embed value types. An entity is a type on its own and has an existence of its own like a Course and its students. A value type is a type which doesn't have existence of its own, but belongs to an entity like an user and his address. Value types are always completely owned by their containing entity. Once you delete the entity, its associated value types are also deleted. But when you delete an entity, referenced entities still exist: when you delete a Course entity, you don't delete all its students.
Submitted by sneha on Tue, 12/18/2012 - 07:50
Pages