Posts

Showing posts from November, 2016

Attribute Override in Hibernate

Image
Model Class /**  *  */ package com.learnjavabyanand; import javax.persistence.AttributeOverride; import javax.persistence.AttributeOverrides; import javax.persistence.Column; import javax.persistence.Embedded; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; /**  * @author ananddw  *  */ @Entity @Table(name="student_details") public class Student { @Id @GeneratedValue(strategy=GenerationType.AUTO) private int studentrollnumber; @Column(name="student_name") private String studentName; @AttributeOverrides({ @AttributeOverride(name="company_location",column=@Column(name="company1_location")), @AttributeOverride(name="company_name",column=@Column(name="company1_name"))}) private CompanyDetails comany_detalils; public CompanyDetails getComany_detali...

Class Embedded In Hibernate

Image
Model Class /**  *  */ package com.learnjavabyanand; import javax.persistence.Column; import javax.persistence.Embedded; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; /**  * @author ananddw  *  */ @Entity @Table(name="student_details") public class Student { @Id @GeneratedValue(strategy=GenerationType.AUTO) private int studentrollnumber; @Column(name="student_name") private String studentName; @Embedded private CompanyDetails comany_detalils; public CompanyDetails getComany_detalils() { return comany_detalils; } public void setComany_detalils(CompanyDetails comany_detalils) { this.comany_detalils = comany_detalils; } public int getStudentrollnumber() { return studentrollnumber; } public void setStudentrollnumber(int studentrollnumber) { this.studentrollnumber...

Auto Increment Column Name in Hibernate

Image
Model Class /**  *  */ package com.learnjavabyanand; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; /**  * @author ananddw  *  */ @Entity @Table(name="student_details") public class Student { @Id @GeneratedValue(strategy=GenerationType.AUTO) private int studentrollnumber; @Column(name="student_name") private String studentName; public int getStudentrollnumber() { return studentrollnumber; } public void setStudentrollnumber(int studentrollnumber) { this.studentrollnumber = studentrollnumber; } public String getStudentName() { return studentName; } public void setStudentName(String studentName) { this.studentName = studentName; } } Client Class:  package com.learnjavabyanand; import org.hibernate.Session; i...

Retrive Obect In Hibernate

Image
Model Class package com.learnjavabyanand; import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; /**  * @author ananddw  *  */ //@Entity will create table as per class name By if you specify name then table name must be the name what you will provide inside Entity @Entity(name="employee_Details") public class EmployeeDetails { //we can put this annotation above getter as well @Id @Column(name="employee_name") private String employeeName; //ignore this variable and not create column for us private String employeeNumber; @Column(name="employee_location") private String employeeLocation ; //Used because to store Date not full time stamp @Temporal(TemporalType.DATE) private Date todayDate; public String getEmployeeName() { return empl...

Transiant ,Temporaland table Annotation in Hibernate

Image
Model Class:  package com.learnjavabyanand; import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; /**  * @author ananddw  *  */ //@Entity will create table as per class name By if you specify name then table name must be the name what you will provide inside Entity @Entity(name="employee_Details") public class EmployeeDetails { //we can put this annotation above getter as well @Id @Column(name="employee_name") private String employeeName; //ignore this variable and not create column for us @Transient private String employeeNumber; @Column(name="employee_location") private String employeeLocation ; //Used because to store Date not full time stamp @Temporal(TemporalType.DATE) private Date todayDate; public String getEmployeeName()...

HiberNate Simple Application Using Annotation

Image
Model Class:  package com.learnjavabyanand; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; /**  * @author ananddw  *  */ //@Entity will create table as per class name By if you specify name then table name must be the name what you will provide inside Entity @Entity(name="employee_Details") public class EmployeeDetails { //we can put this annotation above getter as well @Id @Column(name="employee_name") private String employeeName; @Column(name="employee_number") private String employeeNumber; @Column(name="employee_location") private String employeeLocation ; public String getEmployeeName() { return employeeName; } public void setEmployeeName(String employeeName) { this.employeeName = employeeName; } public String getEmployeeNumber() { return employeeNumber; } public void setEmployeeNumber(String employeeNumber) { this.employeeNum...