Understanding Hibernate
Suppose we have simple message board that contain three classes

If we using JDBC, we have to maintain the relationship between Topic and Post manually, but if we use Hibernate, hibernate will do it for us.
The Steps To Using Hibernate
- Create object model (POJO) for the class
- Configure the mapping file, this is connector between your database schema with your POJO
- Build database schema
- Configure hibernate
Step 1.
We create POJO for the class (Topic class, Post class and User class)
package discussion
import java.util.*;
public class User{
private String id =null;
private String password = null;
/**
* we need constructor without parameter
* because hibernate needed
*/
public User(){}
public User(String id, String password){
this.id=id;
this.password=password;
}
public String getId(){
return id;
}
public void setId(String id){
this.id=id;
}
public String getPassword(){
return password;
}
public void setPassword(String password){
this.password=password;
}
}
/**
* Topic class
*/
public class Topic{
private String id=null;
private Date timestamp=new Date();
private Date modified = new Date();
private List posts = new ArrayList();
public Topic(){}
public String getId(){ return id; }
public void setId(String id){ this.id =id; }
public Date getTimestamp(){ return timestamp; }
public void setTimestamp(Date timestamp){this.timestamp=timestamp;}
public Date getModified(){ return modified;}
public void setModified(Date modified){this.modified=modified;}
public List getPosts(){retun posts;}
public void setPosts(List p){this.posts=p;}
}
/**
* Class Topic
*/
public class Post{
private Long id;
private String subjct;
private String text;
private User user;
public Post(){}
public String getId(){ return id; }
public void setId(String id){ this.id =id; }
public Date getTimestamp(){ return timestamp; }
public void setTimestamp(Date timestamp){this.timestamp=timestamp;}
public Date getModified(){ return modified;}
public void setModified(Date modified){this.modified=modified;}
public List getPosts(){retun posts;}
public void setPosts(List p){this.posts=p;}
}
After finished, then create mapping. The mapping will be describe in chapter 2
April 6, 2009 at 5:44 am
nice post.. i wrote similar topic in my blog.. but i wrote it in indonesian.. please blogwalking..
thx…
April 6, 2009 at 5:50 am
Thank you, may be we could learn together in more deeper undertanding about this topic.
Btw, where`s your blog url?
April 6, 2009 at 6:24 am
oopss.. sorry.. i though it will appear automatically.. cause i wrote this comment while i log in to account of my blog…
here’s my blog http://gienvision.wordpress.com/
April 15, 2009 at 12:14 pm
i have translate some of my article to english..
u can see this on http://gienvision-en.blogspot.com/