Every application requires lookup(s). In computing terms “Lookup” is an array of data, eventually that will be used by most of the applications. One good example is list of Countries. Let us create necessary POJI and POJO classes. A simple country object requires country id and country name. Country Id is normally used a primary key to identify and pick the specific country. Let us create our Country POJI.
package com.omni.services.country;
public interface Country {
public String getCountryId();
public void setCountryId(String countryId);
public String getCountryName();
public void setCountryName(String countryName);
}
Let us start creating Country POJO which is the implementation of Country POJI
package com.omni.services.country.impl;
import com.omni.services.country.Country;
import java.io.*;
public class CountryImpl implements Country, Serializable {
private String countryId = “”;
private String countryName = “”;
public String getCountryId() {
return countryId;
}
public void setCountryId(String countryId) {
this.countryId = countryId;
}
public String getCountryName() {
return countryName;
}
public void setCountryName_en(String countryName_en) {
this.countryName_en = countryName_en;
}
}
This POJO needs to be mapped with a hibernate mapping file. Following code represents Hibernate mapping file.
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE hibernate-mapping PUBLIC “-//Hibernate/Hibernate Mapping DTD 2.0//EN” “http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd“>
<hibernate-mapping>
<class name=”com.omni.services.country.impl.CountryImpl” table=”CountryImpl”>
<id name=”countryId” column = “countryId” type=”java.lang.String” length=”32″>
<generator class=”uuid.hex”/>
</id>
<property name=”countryShortDesc” type=”string” column=”countryShortDesc”/>
<property name=”countryLongDesc” type=”string” column=”countryLongDesc”/>
</class>
</hibernate-mapping>
Hibernate mapping documents are straight forward. The <class> element maps a table with corresponding class. The <id> element represents the primary key column, and its associated attribute in the domain object. The <property> elements represent all other attributes available in the domain object
Filed under: Portlet Development | Tagged: Micro Circle, OMNI, Persistence, Portal