
How do you map Java Objects with Database tables?

Hi Friends, There are to way for mapping of our java object to database..
Using annotation..
package net.roseindia.Model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "userinfo")
public class AddInformation implements Serializable {
private String firstname;
private int id;
@Id
@GeneratedValue
@Column(name = "id")
public int getId() {
return id;
}
@Column(name = "firstname")
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public void setId(int id) {
this.id = id;
}
}
By using hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="true" default-lazy="true">
<class name="net.roseindia.model.EmployeeInfoModel" table="employeeinfo">
<id name="id" column="id" type="java.lang.Integer">
<generator class="increment" />
</id>
<property name="name" column="name" type="java.lang.String" />
<property name="address" column="address" type="java.lang.String" />
</class>
</hibernate-mapping>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.