Magazine
 
Integrating Struts and Hibernate
 

not-null=”true”
length=”100"
/>
</class>
</hibernate-mapping>

Place Tutorial.hbm.xml file in the source
directory e.g. “C:\Struts-Hibernate-
Integration\code\src\java\roseindia\net\dao\
hibernate\”.


POJO Object
Here is the code of Java Bean object (Tutorial.java) used to store and retrieve the data from database.

package roseindia.net.dao.hibernate;
import java.io.Serializable;
public class Tutorial implements Serializable {
/** identifier field */
private Integer id;
/** persistent field */
private String shortdesc;
/** persistent field */
private String longdesc;
/** persistent field */
private String pageurl;
/** full constructor */
public Tutorial(Integer id, String shortdesc,
String longdesc, String pageurl) {
this.id = id;
this.shortdesc = shortdesc;
this.longdesc = longdesc;
this.pageurl = pageurl;
}
/** default constructor */
public Tutorial() {
}
public Integer getId() {
return this.id;
}

 

public void setId(Integer id) {
this.id = id;
}
public String getShortdesc() {
return this.shortdesc;
}
public void setShortdesc(String shortdesc)
{
this.shortdesc = shortdesc;
}
public String getLongdesc() {
return this.longdesc;
}
public void setLongdesc(String longdesc) {
this.longdesc = longdesc;
}
public String getPageurl() {
return this.pageurl;
}
public void setPageurl(String pageurl) {
this.pageurl = pageurl;
}
}

In this section we have created all the Hibernate related stuffs.

4. Developing Struts Hibernate Plugin
In this section, we will develop java code for Struts Hibernate Plugin. Our Hibernate Plugin will create Hibernate Session factory and cache it in the servlet context. This strategy enhances the performance of the application.

Source Code Of Hibernate Struts Plugin: package
package roseindia.net.plugin;

import java.net.URL;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.apache.commons.logging.Log;

Dec 2007 | Java Jazz Up | 56
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 ,

Download PDF