Skip to main content

Posts

Showing posts from August, 2014

Hibernate @NotFound Annotation

Hibernate provides the annotation @NotFound .  This annotation can be used in cases where we have relationships between the Entities e.g. ManyToOne or OneToMany or ManyToMany etc. Syntax - @NotFound(action=NotFoundException.IGNORE) When we want to access an entity using the relation from another entity, if the value of this entity is not available then the hibernate throws an exception. We  can use @NotFound annotation to ignore these exceptions.  NotFoundException.IGNORE tells the hibernate to avoid throwing the exception if the record for the entity is not found. @Entity(name="user") @Table(name="user") public class User{ }

Hibernate Primary Key Generation Strategies

There are 4 types of Generation Strategies that can be used to generate Id in hibernate. AUTO   e.g. strategy = GenerationType.AUTO IDENTITY  e.g. strategy = GenerationType.IDENTITY SEQUENCE  e.g. strategy = GenerationType.SEQUENCE TABLE  e.g. strategy = GenerationType.TABLE strategy = GenerationType.AUTO This is the default Generation Strategy that is used by the hibernate. This strategy allows hibernate to decide what strategy to be used to generate the unique key for the table. Strategies used by hibernate can be different for different types of databases used. strategy = GenerationType.IDENTITY In this Generation Strategy the hibernate is going to use an identity column. Identity column is a feature that is provided in some of the databases, this is not a generic feature and is provided by a few databases only. strategy = GenerationType.SEQUENCE In this Generation Strategy, the hibernate generate unique keys by a sequence hilo. This uses a sequence object to generate a sequence o

Difference between Grails Respond and Grails Render

First things that comes in mind Respond was introduced in Grails v2.3. Render is used by Grails to render different forms of responses from simple text response, to views to templates. Respond automatically attempts to return the most appropriate type for the requested content type. Respond is a better version of render, and can do everything render does. Example In case you want to send data to the view in "xml" or in "json" format then you will have to do the following render :  // renders text for a specified content-type/encoding render(text: " some xml ", contentType: "text/xml", encoding: "UTF-8" render(text: " some json ", contentType: "text/json", encoding: "UTF-8" respond :  by using respond, it will automatically select the correct return type respond( text: "some text in json or xml" [formats : ['xml' , 'json']]) it will automatically send the required respond depending

What are Objects In Java

First things that comes in mind are They are real things They occupy some space in memory They have a state and some characteristics Definition Java Objects are the real world entities that can have a state and some behavior. They are created from a blueprint i.e. classes. Example If we say that Person is a class, then person is a blue print of every human in this world and we are all the objects of this class Person. Since each object has some state and some characteristics, thus we may be similar or different from each other ion the basis of these states or characteristics. The image below shows a Class - "Person" and its objects Elaya, Dara and Bharat.