Home  >  Hibernate

Transient Property in Hibernate

By Arvind Rai, May 12, 2013
Transient Property is that property which will not persist. In hibernate, property can be transient by two way.

1. Make the variable transient
2. Use @Transient annotation.

User.java
package com.concretepage.persistence;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name="user")  
public class User {
	@Id
	@GeneratedValue
	private int id;  //persistent property
		
	@Column(name="name")  
	private transient String name;  //non persistent property 
	
	@Transient
	@Column(name="age")
	private int age;        //non persistent property

	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
}
 
POSTED BY
ARVIND RAI
ARVIND RAI
FIND MORE TUTORILAS


©2018 concretepage.com | Privacy Policy | Contact Us