Tuesday, May 15, 2012

what is @Transient annotation in hibernate

let consider the below java bean defination




package com.yagapps.hibernate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;


@Entity
public class College {


private String name;
private String address;
private String id;


public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

@Id
@Column(name="myname")
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Column(name="myadd")
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}

hibernate will create a table with the name college which contains three columns, related to each field in the above java bean , but if u don';t want one field as a column in that table then u can make or associate @Transient annotation on that field as below



@Transient
public String getId() {
return id;
}




11 comments: