<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Me and my chaotic life</title>
	<atom:link href="http://singgihpraditya.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://singgihpraditya.wordpress.com</link>
	<description></description>
	<lastBuildDate>Sun, 26 Dec 2010 06:04:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='singgihpraditya.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Me and my chaotic life</title>
		<link>http://singgihpraditya.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://singgihpraditya.wordpress.com/osd.xml" title="Me and my chaotic life" />
	<atom:link rel='hub' href='http://singgihpraditya.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Spring 3.0 and Hibernate tutorial (part 1)</title>
		<link>http://singgihpraditya.wordpress.com/2010/02/13/spring-3-0-and-hibernate-tutorial-part-1/</link>
		<comments>http://singgihpraditya.wordpress.com/2010/02/13/spring-3-0-and-hibernate-tutorial-part-1/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 07:02:22 +0000</pubDate>
		<dc:creator>singgihpraditya</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://singgihpraditya.wordpress.com/?p=172</guid>
		<description><![CDATA[In my previous spring tutorial, i&#8217;ve given simple example how to integrating Spring Framework with Hibernate through JPA. Now i&#8217;ll show you how to engaging Spring with Hibernate using Hibernate template on Spring. It&#8217;s easier than you connect using JPA. Because spring already build hibernate support. First of all, we need to create entity class. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=singgihpraditya.wordpress.com&amp;blog=2270691&amp;post=172&amp;subd=singgihpraditya&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my <a title="Spring JPA" href="http://singgihpraditya.wordpress.com/2009/03/19/simple-maven2-spring-25-jpa-and-hibernate-integration/">previous</a> spring tutorial, i&#8217;ve given simple example how to integrating Spring Framework with Hibernate through JPA. Now i&#8217;ll show you how to engaging Spring with Hibernate using Hibernate template on Spring. It&#8217;s easier than you connect using JPA. Because spring already build hibernate support.<span id="more-172"></span></p>
<p>First of all, we need to create entity class. Lets give  it User class, this will be  located on org.adit.spring.hibernate.entity package. Following is the content of User.java</p>
<pre class="brush: java;">
package org.adit.spring.hibernate.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = &quot;user&quot;)
public class User implements Serializable {
	/**
	 *
	 */
	private static final long serialVersionUID = 8496087166198616020L;
	private String userId;
	private String userName;
	private Integer age;
	private Boolean registered;

	@Id
	@GeneratedValue(generator = &quot;system-uuid&quot;)
	@GenericGenerator(name = &quot;system-uuid&quot;, strategy = &quot;uuid&quot;)
	@Column(name = &quot;userId&quot;)
	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}
	@Column(name = &quot;userName&quot;, nullable=false)
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}
	@Column(name = &quot;age&quot;)
	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}
	@Column(name = &quot;registered&quot;, nullable=false)
	public Boolean getRegistered() {
		return registered;
	}

	public void setRegistered(Boolean registered) {
		this.registered = registered;
	}
}
</pre>
<p>As you can see, i&#8217;m using generator approach, so Id of this record on database will automatically created , so you don&#8217;t need to set this entity Id or make this field auto generated when you create the table.</p>
<p>Second, we created DAO class, because just like  i told you before it gonna be simple example. So we just only create 4 basic method. Create, Retrtieve, Update and Delete (CRUD). Below is the interface of UserDao.java</p>
<pre class="brush: java;">
package org.adit.spring.hibernate.dao;

import java.util.List;

import org.adit.spring.hibernate.entity.User;

public interface UserDao {
	public void saveUser(User user);
	public List&lt;User&gt; getAllUser(User user);
	public User selectUserById(String userId);
	public void deleteUser(User user);
}
</pre>
<p>And, we have to implement this interface with this class</p>
<pre class="brush: java;">
package org.adit.spring.hibernate.dao;

import java.util.List;

import org.adit.spring.hibernate.entity.User;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

//This will make easier to autowired
@Repository(&quot;userDao&quot;)
// Default is read only
@Transactional
public class UserDaoImpl implements UserDao {
	private HibernateTemplate hibernateTemplate;

	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		hibernateTemplate = new HibernateTemplate(sessionFactory);
	}

	@Transactional(readOnly = false)
	public void saveUser(User user) {
		hibernateTemplate.saveOrUpdate(user);

	}

	@Transactional(readOnly = false)
	public void deleteUser(User user) {
		hibernateTemplate.delete(user);

	}

	@SuppressWarnings(&quot;unchecked&quot;)
	public List&lt;User&gt; getAllUser(User user) {
		return (List&lt;User&gt;) hibernateTemplate.find(&quot;from &quot;
				+ User.class.getName());
	}

	public User selectUserById(String userId) {
		return hibernateTemplate.get(User.class, userId);
	}

}
</pre>
<p>Class UserDaoImpl have added @Repository annotation, so we don&#8217;n need to write this dao into Spring beans configuration. This class already auto scanned.</p>
<p>Ok now, we created Spring configuration file. I deliberately separated configuration into small pieces, so it&#8217;s will easier for us, when maintenance or change our code in the future. Main configuration is app-config.xml. Contains general configuration for application.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
	xsi:schemaLocation=&quot;
		http://www.springframework.org/schema/beans	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd&quot;&gt;

	&lt;bean id=&quot;propertyConfigurer&quot;
		class=&quot;org.springframework.beans.factory.config.PropertyPlaceholderConfigurer&quot;&gt;
		&lt;property name=&quot;locations&quot;&gt;
			&lt;list&gt;
				&lt;value&gt;/configuration.properties&lt;/value&gt;
			&lt;/list&gt;
		&lt;/property&gt;
	&lt;/bean&gt;

	&lt;context:component-scan base-package=&quot;org.adit.spring&quot; /&gt;
	&lt;import resource=&quot;db-config.xml&quot; /&gt;
&lt;/beans&gt;
</pre>
<p>Second configuration is db-config.xml. This file purposes for saving configuration of datasource and ORM settings.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:p=&quot;http://www.springframework.org/schema/p&quot;
	xmlns:context=&quot;http://www.springframework.org/schema/context&quot; xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot;
	xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
	&quot;&gt;
	&lt;bean id=&quot;dataSource&quot; class=&quot;com.mchange.v2.c3p0.ComboPooledDataSource&quot;
		destroy-method=&quot;close&quot;&gt;

		&lt;property name=&quot;driverClass&quot;&gt;
			&lt;value&gt;${jdbc.driver.className}&lt;/value&gt;
		&lt;/property&gt;
		&lt;property name=&quot;jdbcUrl&quot;&gt;
			&lt;value&gt;${jdbc.url}&lt;/value&gt;
		&lt;/property&gt;
		&lt;property name=&quot;user&quot;&gt;
			&lt;value&gt;${jdbc.username}&lt;/value&gt;
		&lt;/property&gt;
		&lt;property name=&quot;password&quot;&gt;
			&lt;value&gt;${jdbc.password}&lt;/value&gt;
		&lt;/property&gt;
	&lt;/bean&gt;
	&lt;bean id=&quot;sessionFactory&quot;
		class=&quot;org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean&quot;&gt;
		&lt;property name=&quot;dataSource&quot;&gt;
			&lt;ref bean=&quot;dataSource&quot; /&gt;
		&lt;/property&gt;
		&lt;property name=&quot;packagesToScan&quot; value=&quot;org.adit.spring.hibernate.entity&quot; /&gt;
		&lt;property name=&quot;hibernateProperties&quot;&gt;
			&lt;props&gt;
				&lt;prop key=&quot;hibernate.dialect&quot;&gt;${jdbc.hibernate.dialect}&lt;/prop&gt;
				&lt;prop key=&quot;hibernate.hbm2ddl.auto&quot;&gt;create&lt;/prop&gt;
				&lt;!-- uncomment this for first time run--&gt;
				&lt;prop key=&quot;hibernate.hbm2ddl.auto&quot;&gt;create&lt;/prop&gt;
				&lt;prop key=&quot;hibernate.show_sql&quot;&gt;false&lt;/prop&gt;
			&lt;/props&gt;
		&lt;/property&gt;
	&lt;/bean&gt;
	&lt;bean id=&quot;transactionManager&quot;
		class=&quot;org.springframework.orm.hibernate3.HibernateTransactionManager&quot;&gt;
		&lt;property name=&quot;sessionFactory&quot;&gt;
			&lt;ref bean=&quot;sessionFactory&quot; /&gt;
		&lt;/property&gt;
	&lt;/bean&gt;
	&lt;tx:annotation-driven /&gt;
&lt;/beans&gt;
</pre>
<p>I suggest to separate editable property into different file. So when we have to edit or change some property only this configuration.properties is changed.</p>
<pre class="brush: java;">
jdbc.driver.className=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/springhibernate
jdbc.username=yourusername
jdbc.password=yourpassword
jdbc.hibernate.dialect=org.hibernate.dialect.MySQLDialect
</pre>
<p>For the last, write an unit testing class, Spring has good support for JUnit, it makes us testing painless. This is our unit testing class</p>
<pre class="brush: java;">
package test.adit.spring.hibernate;

import java.util.List;

import junit.framework.Assert;

import org.adit.spring.hibernate.dao.UserDao;
import org.adit.spring.hibernate.entity.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( { &quot;/app-config.xml&quot; })
public class UserTest {
	private UserDao dao;

	@Autowired
	public void setDao(UserDao dao) {
		this.dao = dao;
	}

	@Test
	public void testCreateData() {
		int expectedResult = 1;
		User user = new User();
		user.setAge(23);
		user.setUserName(&quot;Adit&quot;);
		user.setRegistered(true);
		dao.saveUser(user);
		Assert.assertEquals(expectedResult, dao.getAllUser(new User()).size());
	}

	@Test
	public void testRetrieveData() {
		List&lt;User&gt; userList = dao.getAllUser(new User());
		Assert.assertEquals(1, userList.size());
		User userExpected = userList.get(0);
		User userResult = dao.selectUserById(userExpected.getUserId());
		Assert.assertEquals(userExpected.getUserId(), userResult.getUserId());
	}

	@Test
	public void testUpdateData() {
		List&lt;User&gt; userList = dao.getAllUser(new User());
		Assert.assertEquals(1, userList.size());
		User userExpected = userList.get(0);
		userExpected.setUserName(&quot;Singgih&quot;);
		dao.saveUser(userExpected);
		User userResult = dao.selectUserById(userExpected.getUserId());
		Assert.assertEquals(userExpected.getUserName(), userResult
				.getUserName());
	}

	@Test
	public void testDeleteData() {
		List&lt;User&gt; userList = dao.getAllUser(new User());
		Assert.assertEquals(1, userList.size());
		User userExpected = userList.get(0);
		dao.deleteUser(userExpected);
		User userResult = dao.selectUserById(userExpected.getUserId());
		Assert.assertEquals(userResult, null);
	}
}
</pre>
<p>You can browse mavenize source code of this tutorial <a title="repository" href="http://code.google.com/p/the-nest/source/browse/">here</a>. Or check out directly using subversion using :</p>
<pre class="brush: java;">
svn checkout http://the-nest.googlecode.com/svn/trunk/java/spring-hibernate1 spring-hibernate1
</pre>
<p>Next part i&#8217;ll show how to build relations between tables in database</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/singgihpraditya.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/singgihpraditya.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/singgihpraditya.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/singgihpraditya.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/singgihpraditya.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/singgihpraditya.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/singgihpraditya.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/singgihpraditya.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/singgihpraditya.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/singgihpraditya.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/singgihpraditya.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/singgihpraditya.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/singgihpraditya.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/singgihpraditya.wordpress.com/172/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=singgihpraditya.wordpress.com&amp;blog=2270691&amp;post=172&amp;subd=singgihpraditya&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://singgihpraditya.wordpress.com/2010/02/13/spring-3-0-and-hibernate-tutorial-part-1/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bf2e570e92acba054ae63f3484167850?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">adit</media:title>
		</media:content>
	</item>
		<item>
		<title>I&#8217;ll do anything for bandwidth</title>
		<link>http://singgihpraditya.wordpress.com/2010/01/31/ill-do-anything-for-bandwidth/</link>
		<comments>http://singgihpraditya.wordpress.com/2010/01/31/ill-do-anything-for-bandwidth/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 05:46:54 +0000</pubDate>
		<dc:creator>singgihpraditya</dc:creator>
				<category><![CDATA[MyLife]]></category>

		<guid isPermaLink="false">http://singgihpraditya.wordpress.com/?p=149</guid>
		<description><![CDATA[Tulisan ini sebenernya catatan dari keisengan gw. Beberapa waktu yang lalu gw beli antena 3g, sengaja gw beli karena gw sudah mulai bosen koneksi internet yang empot-empotan di rumah karena kurangnya signal di rumah gw. Apes emang, kondisi rumah gw yang jauh dari pusat kota bikin  sinyal (gak cuma sinyal hape, tv atau radio juga) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=singgihpraditya.wordpress.com&amp;blog=2270691&amp;post=149&amp;subd=singgihpraditya&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Tulisan ini sebenernya catatan dari keisengan gw. Beberapa waktu yang lalu gw beli antena 3g, sengaja gw beli karena gw sudah mulai bosen koneksi internet yang empot-empotan di rumah karena kurangnya signal di rumah gw. Apes emang, kondisi rumah gw yang jauh dari pusat kota bikin  sinyal (gak cuma sinyal hape, tv atau radio juga) amat lemah di tempat gw. Boro-boro dapat sinyal 3g atau HSDPA, GPRS pun kadang-kadang susah. Apalagi di musim hujan kayak sekarang, susah banget nyambung. So, gw akhirnya beli antena 3g, gw beli yang kecilan dulu (7db), buat coba-coba. Lumayan bisa naik segitu dari sinyal rata-rata (&lt; -100db), (Secara teory) cukup buat 1 bar sinyal 3g.</p>
<p><span id="more-149"></span>Sial, ternyata gak ngaruh. Di percobaan pertama, gw pasang antena di kamar gw, gw arahkan keluar, sinyal tetep gak naik. Gw penasaran apa antenanya yang rusak (putus atau lost di jalan). Gw lakukan percobaan kedua. Luar ruangan. gw posisikan laptop gw di bawah, cukup terhalang tembok. Sengaja gw letakkan di situ biar modem gak dapat signal. satu-satunya signal ya dari antena. Sementara antena gw letakkan di atas loteng. Hasilnya lumayan. signal naek, tapi tetap gak sesuai harapan. It&#8217;s ok, karena gw memang beli antena yang gain-nya kecil.</p>
<p>Laptopnya :</p>
<p style="text-align:center;"><img class="aligncenter" title="Laptop di bawah" src="http://s6.tinypic.com/2n0q845.jpg" alt="" width="640" height="480" /></p>
<p>Ini antenanya :</p>
<p style="text-align:center;"><img class="aligncenter" title="Antena di loteng" src="http://s6.tinypic.com/169kn11.jpg" alt="" width="360" height="480" /></p>
<p>Hasilnya :</p>
<p style="text-align:center;"><img class="aligncenter" title="Result" src="http://s6.tinypic.com/vxdnja.jpg" alt="" width="466" height="666" /></p>
<p>Akhirnya, karena penasaran gw bawa laptop gw ke (ujung) genteng. gw pengen lihat sebenarnya signal di tempat gw sebesar apa. Hasilnya emang dudul. signal maksimal hanya -93 db.</p>
<p style="text-align:center;"><img class="aligncenter" title="Laptop di atas genteng" src="http://s6.tinypic.com/33l00vt.jpg" alt="" width="360" height="480" /></p>
<p>Wakaka, jadi ya emang bener-bener kacau signal di tempat gw, nasib-nasib!. Solusinya ya mungkin beli antena yang gain-nya lebih tinggi atau ganti operator kali.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/singgihpraditya.wordpress.com/149/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/singgihpraditya.wordpress.com/149/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/singgihpraditya.wordpress.com/149/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/singgihpraditya.wordpress.com/149/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/singgihpraditya.wordpress.com/149/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/singgihpraditya.wordpress.com/149/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/singgihpraditya.wordpress.com/149/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/singgihpraditya.wordpress.com/149/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/singgihpraditya.wordpress.com/149/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/singgihpraditya.wordpress.com/149/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/singgihpraditya.wordpress.com/149/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/singgihpraditya.wordpress.com/149/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/singgihpraditya.wordpress.com/149/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/singgihpraditya.wordpress.com/149/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=singgihpraditya.wordpress.com&amp;blog=2270691&amp;post=149&amp;subd=singgihpraditya&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://singgihpraditya.wordpress.com/2010/01/31/ill-do-anything-for-bandwidth/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bf2e570e92acba054ae63f3484167850?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">adit</media:title>
		</media:content>

		<media:content url="http://s6.tinypic.com/2n0q845.jpg" medium="image">
			<media:title type="html">Laptop di bawah</media:title>
		</media:content>

		<media:content url="http://s6.tinypic.com/169kn11.jpg" medium="image">
			<media:title type="html">Antena di loteng</media:title>
		</media:content>

		<media:content url="http://s6.tinypic.com/vxdnja.jpg" medium="image">
			<media:title type="html">Result</media:title>
		</media:content>

		<media:content url="http://s6.tinypic.com/33l00vt.jpg" medium="image">
			<media:title type="html">Laptop di atas genteng</media:title>
		</media:content>
	</item>
		<item>
		<title>Howto install and configure dual boot Kalyway OSX86 and Ubuntu</title>
		<link>http://singgihpraditya.wordpress.com/2009/11/28/howto-install-and-configure-dual-boot-kalyway-osx86-and-ubuntu/</link>
		<comments>http://singgihpraditya.wordpress.com/2009/11/28/howto-install-and-configure-dual-boot-kalyway-osx86-and-ubuntu/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 08:38:10 +0000</pubDate>
		<dc:creator>singgihpraditya</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OSX86]]></category>

		<guid isPermaLink="false">http://singgihpraditya.wordpress.com/?p=109</guid>
		<description><![CDATA[Disclaimer : Let&#8217;s assume it just preview of Mac OS X Leopard, if you like this operating system and want to use Mac OS for daily use. please buy legal Mac OS Xversion, No guarantee if result of this tutorial will working properly in your box/machine and i&#8217;m not responsible if there&#8217;s a damages happen [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=singgihpraditya.wordpress.com&amp;blog=2270691&amp;post=109&amp;subd=singgihpraditya&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Disclaimer : </strong><br />
Let&#8217;s assume it just preview of Mac OS X Leopard, if you like this operating system and want to use Mac OS for daily use. please buy legal Mac OS Xversion,  No guarantee if result of this tutorial will working properly in your box/machine and i&#8217;m not responsible if there&#8217;s a damages happen during or after installation process. However, Leopard officially worked only in Mac machine, others are illegal. If you understand and realized the risks, here we go.<span id="more-109"></span></p>
<p>First, make sure our PC passed requirements below:</p>
<ol>
<li> x86 SSE2 CPU (SSE3 for running PPC Apps),</li>
<li> 512MB RAM</li>
<li> 10GB free space on target partition,</li>
<li> OpenGL suported VGA card, optional but i guess you won&#8217;t missing OSX desktop effect right?.</li>
</ol>
<p>Second, because alot of variation of PC hardware spesification, we need to know deeply our hardware. this is important cause different hardware means different approach. Ok my pc spesification is:</p>
<ol>
<li> Acer 4715z with 1.4 Ghz dual core, CPU SSE3 supported</li>
<li>2 GB DDR2-SDRAM</li>
<li>Intel GMA X3100 graphics card</li>
<li> Acer CrystalEye Webcam</li>
<li>Marvell. 88E8039 PCI-E Fast Ethernet Controller</li>
<li> Atheros. AR5001 Wireless Network Adapter</li>
<li> Intel ICH8 Family audio controller</li>
</ol>
<p>And then,  it&#8217;s all we need :</p>
<ol>
<li> Kalyway ( I still use 10.5.2, there is newest version out there. But damn, all ISO are dvd size, i think it will spent half century just for download newest version)</li>
<li> pc_efi_v80 file, both files you can find with uncle google, sorry i forgot the link <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </li>
<li> A bottle of coffee, one pack biscuit, and your favourite music, this progress will take a little bit long, depending to your computer certainly</li>
</ol>
<p>Lets gets party started :</p>
<ol>
<li> Boot your PC with Kalyway DVD, then press F8 for boot option. You can use -v option for displaying verbose output, first boot and hardware identification began</li>
<li> After language selection shows up, choose your language (Ex. English), it will lead you to installation screen</li>
<li> Before you installing system, choose your hardisk partition first, be carefull and ensure to format your Mac OS partition is type Mac OS Extended (Journaled). Press agree to finish <img class="aligncenter" src="http://s6.tinypic.com/30wlg09.jpg" alt="partition" width="576" height="432" /></li>
<li>Choose your partition to install, if you want to costumize package first choose costumize before install. configuration depend on your hardware but for safety, choose only kernel_9.2,speedstep on kernel. And only install what you need to install, if you don&#8217;t want waste your disk space, and unstable system</li>
<li> Then, Install. Enjoy your coffee. restart your computer when finish<img class="aligncenter" src="http://s6.tinypic.com/zvxy7k.jpg" alt="install" width="576" height="432" /></li>
</ol>
<p>Now, configure dual boot option with ubuntu, i&#8217;m using Karmic (9.10) version, unfortunately this version now using GRUB2 version. I got litle problem to configure in that version. So i&#8217;m downgrade my version in legacy. You can read it <a title="back into legacy grub" href="http://singgihpraditya.wordpress.com/2009/11/28/karmic-koala-back-into-legacy-grub/">here</a> to downgrade. If currently GRUB-Legacy, below are step by step to create dual boot options</p>
<ol>
<li>Unzip pc_efi_v80, copy boot_v8 file into grub folder
<pre class="brush: bash;">
sudo cp pc_efi_v80/boot_v8 /boot/grub/
</pre>
</li>
<li>Add this line into /boot/grub/menu.lst file, hd0,4 is my linux partition, where /boot located. maybe different with your machine
<pre class="brush: bash;">
title 	Mac OSX Leopard 10.5.2
kernel (hd0,4)/boot/grub/boot_v8
</pre>
</li>
<li>Install new configuration, you can see my <a href="http://singgihpraditya.wordpress.com/2009/11/28/karmic-koala-back-into-legacy-grub/">latest</a> downgrade tutorial.</li>
</ol>
<p>Restart your PC, if succeed, there will be a new line in grub menu, choose it we will configure Leopard now. if displayed partition type set 80, and it will take you to next step</p>
<ol>
<li> Pick your partition, don&#8217;t boot first, if you dream about beautiful welcome screen, hmm we will not see that. we will configure it via terminal.</li>
<li> Boot with these option, we will go into terminal mode and disable dual core feature
<pre class="brush: bash;">
-s legacy cpus=1
</pre>
</li>
<li>Then after terminal opened type this command, it will cek partition and set set write mode for root partition
<pre class="brush: bash;">
/sbin/fsck -f
/sbin/mount -uw /
</pre>
</li>
<li>Set root password and force system to recognize that we have finished installation
<pre class="brush: bash;">
passwd root ##
touch /var/db/.AppleSetupDone
</pre>
</li>
<li>Now we can exit, and go into Leopard login screen
<pre class="brush: bash;">
exit
</pre>
</li>
</ol>
<p style="text-align:left;"><img class="aligncenter" src="http://s6.tinypic.com/s66tef.jpg" alt="result" width="600" height="375" /><br />
Yipeee, now Leopard is running in your PC ,  next tutorial i&#8217;ll show you how to configure devices like Sound Card, Ethernet Card and 3G modem.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/singgihpraditya.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/singgihpraditya.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/singgihpraditya.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/singgihpraditya.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/singgihpraditya.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/singgihpraditya.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/singgihpraditya.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/singgihpraditya.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/singgihpraditya.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/singgihpraditya.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/singgihpraditya.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/singgihpraditya.wordpress.com/109/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/singgihpraditya.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/singgihpraditya.wordpress.com/109/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=singgihpraditya.wordpress.com&amp;blog=2270691&amp;post=109&amp;subd=singgihpraditya&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://singgihpraditya.wordpress.com/2009/11/28/howto-install-and-configure-dual-boot-kalyway-osx86-and-ubuntu/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bf2e570e92acba054ae63f3484167850?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">adit</media:title>
		</media:content>

		<media:content url="http://s6.tinypic.com/30wlg09.jpg" medium="image">
			<media:title type="html">partition</media:title>
		</media:content>

		<media:content url="http://s6.tinypic.com/zvxy7k.jpg" medium="image">
			<media:title type="html">install</media:title>
		</media:content>

		<media:content url="http://s6.tinypic.com/s66tef.jpg" medium="image">
			<media:title type="html">result</media:title>
		</media:content>
	</item>
		<item>
		<title>Karmic Koala, back into legacy GRUB</title>
		<link>http://singgihpraditya.wordpress.com/2009/11/28/karmic-koala-back-into-legacy-grub/</link>
		<comments>http://singgihpraditya.wordpress.com/2009/11/28/karmic-koala-back-into-legacy-grub/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 06:48:53 +0000</pubDate>
		<dc:creator>singgihpraditya</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://singgihpraditya.wordpress.com/?p=105</guid>
		<description><![CDATA[One of  a lot of new feature of Ubuntu Karmic Koala (9.10) is GRUB2 (GRand Unified Bootloader 2).  GRUB2 has replaced formerly known GRUB-Legacy (0.9x), which no longer being developed. It has significant different comparing with previous version, there is no longer /boot/grub/menu.lst  file, GRUB2 boot menu handled by /boot/grub/grub.cfg. This file automatically generated when [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=singgihpraditya.wordpress.com&amp;blog=2270691&amp;post=105&amp;subd=singgihpraditya&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of  a lot of new feature of Ubuntu Karmic Koala (9.10) is GRUB2 (GRand Unified Bootloader 2).  GRUB2 has replaced formerly known GRUB-Legacy (0.9x), which no longer being developed. It has significant different comparing with previous version, there is no longer /boot/grub/menu.lst  file, GRUB2 boot menu handled by /boot/grub/grub.cfg. This file automatically generated when system boot. but how if we still want to use old stuff, For example, i didn&#8217;t succeed to configure this newest version for pc_efi boot, meanwhile i need this for dual booting with my OSX86. <span id="more-105"></span><br />
First, we need to remove this GRUB2 version</p>
<pre class="brush: bash;">
sudo apt-get --purge remove grub*
</pre>
<p>Remove all files from latest installation</p>
<pre class="brush: bash;">
sudo rm -rf /boot/grub/*
</pre>
<p>Now, installing GRUB legacy</p>
<pre class="brush: bash;">
sudo apt-get install grub
</pre>
<p>Then, we have to generate menu.lst file, which needed for booting</p>
<pre class="brush: bash;">
sudo update-grub
</pre>
<p>You can configure menu.lst file as you needed, and installing to system with this command,</p>
<pre class="brush: bash;">
sudo grub
</pre>
<p>Find where your linux root partision located with :</p>
<pre class="brush: bash;">
find /boot/grub/stage1
</pre>
<p>Set root partition with result of command above, i my case (hd0,4)</p>
<pre class="brush: bash;">
root (hd0,4)
</pre>
<p>Install into MBR, normally hd0, maybe different in your machine</p>
<pre class="brush: bash;">
setup (hd0)
</pre>
<p>Bingo, now your GRUB back to legacy. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/singgihpraditya.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/singgihpraditya.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/singgihpraditya.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/singgihpraditya.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/singgihpraditya.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/singgihpraditya.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/singgihpraditya.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/singgihpraditya.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/singgihpraditya.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/singgihpraditya.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/singgihpraditya.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/singgihpraditya.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/singgihpraditya.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/singgihpraditya.wordpress.com/105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=singgihpraditya.wordpress.com&amp;blog=2270691&amp;post=105&amp;subd=singgihpraditya&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://singgihpraditya.wordpress.com/2009/11/28/karmic-koala-back-into-legacy-grub/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bf2e570e92acba054ae63f3484167850?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">adit</media:title>
		</media:content>
	</item>
		<item>
		<title>LG-KU250 Storage Mode got problem in Karmic Koala</title>
		<link>http://singgihpraditya.wordpress.com/2009/11/08/lg-ku250-storage-mode-got-problem-in-karmic-koala/</link>
		<comments>http://singgihpraditya.wordpress.com/2009/11/08/lg-ku250-storage-mode-got-problem-in-karmic-koala/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 11:54:54 +0000</pubDate>
		<dc:creator>singgihpraditya</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://singgihpraditya.wordpress.com/?p=85</guid>
		<description><![CDATA[I got litle trouble after upgrading to karmic koala, since the upgrade I&#8217;ve had problems with usb-storage. After i plug the device, system not mount anything. Actually this issue happened in Jaunty, but finally working after i did litle trick, add this line into /etc/modules : usb-storage option_zero_cd=2 But in Karmic, it doesn&#8217;t work as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=singgihpraditya.wordpress.com&amp;blog=2270691&amp;post=85&amp;subd=singgihpraditya&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I got litle trouble  after upgrading to karmic koala, since the upgrade I&#8217;ve had problems with usb-storage. After i plug the device, system not mount anything.  Actually this issue  happened in  Jaunty, but finally working after i did litle trick, add this line into /etc/modules : </p>
<pre class="brush: bash;">
usb-storage option_zero_cd=2
</pre>
<p>But in Karmic, it doesn&#8217;t work as i expected .  This problem happened because device id  05c6:1000  is not initialized correctly and stopped with result :</p>
<pre class="brush: bash;">
[  144.565583] usb 2-1: configuration #1 chosen from 1 choice
[  144.576078] usb-storage: probe of 2-1:1.0 failed with error -5
</pre>
<p>So i guess this happened in all devices  which share these IDs (used by a Qualcomm chipset for storage device)<br />
I wish i can find a solution immediately, Damn, i&#8217;ts so annoying if i remove first memory card from my mobile phone, then connected through Card Reader just for data exchange</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/singgihpraditya.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/singgihpraditya.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/singgihpraditya.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/singgihpraditya.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/singgihpraditya.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/singgihpraditya.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/singgihpraditya.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/singgihpraditya.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/singgihpraditya.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/singgihpraditya.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/singgihpraditya.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/singgihpraditya.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/singgihpraditya.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/singgihpraditya.wordpress.com/85/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=singgihpraditya.wordpress.com&amp;blog=2270691&amp;post=85&amp;subd=singgihpraditya&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://singgihpraditya.wordpress.com/2009/11/08/lg-ku250-storage-mode-got-problem-in-karmic-koala/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bf2e570e92acba054ae63f3484167850?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">adit</media:title>
		</media:content>
	</item>
		<item>
		<title>Solving Eclipse Galileo problem in Karmic Koala (Ubuntu 9.10)</title>
		<link>http://singgihpraditya.wordpress.com/2009/11/04/solving-eclipse-galileo-problem-in-karmic-koala-ubuntu-9-10/</link>
		<comments>http://singgihpraditya.wordpress.com/2009/11/04/solving-eclipse-galileo-problem-in-karmic-koala-ubuntu-9-10/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 14:04:45 +0000</pubDate>
		<dc:creator>singgihpraditya</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://singgihpraditya.wordpress.com/?p=74</guid>
		<description><![CDATA[Yesterday i&#8217;ve upgraded my ubuntu with latest version 9.10 (Karmic Koala). After installing a lot of application, i was trying to install my favorite IDE, Eclipse 3.5 (Galileo). but something goes wrong after. i was not able to push OK button or Cancel button etc. At that time i tought that main problem is my [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=singgihpraditya.wordpress.com&amp;blog=2270691&amp;post=74&amp;subd=singgihpraditya&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Yesterday i&#8217;ve upgraded my  ubuntu  with latest version 9.10 (Karmic Koala). After installing a lot of application, i was trying to install my favorite IDE, Eclipse 3.5 (Galileo). but something goes wrong after. i was not able to push OK button or Cancel button etc.<br />
At that time i tought that main problem is my eclipse. Before i upgraded to karmic. i was install some plugins. that doesn&#8217;t matter in 9.04. but after install fresh copier of Galileo  i still found this problem. Finally i found it, the main problem is about in how eclipse use GTK. In linux eclipse use GTK Library for handling interface, so it can be more native look.  <span id="more-74"></span><br />
From what i was read <a href="https://bugs.launchpad.net/ubuntu/+source/gtk+2.0/+bug/442078/comments/28">here</a></p>
<blockquote><p>
Starting from 2.18 on, GTK+ changed some of its internal behaviour (google for &#8220;client side windows&#8221;). This change is intentional, and needed for other development. It doesn&#8217;t make any difference to programs using GTK+ correctly, but it makes problems with programs that use GTK+ in weird ways, making wrong assumptions that only accidentally worked in the past. So, to ease the transition until those programs get fixed, an environment variable has been introduced to simulate the old behaviour.</p>
<p>So it&#8217;s really up to the eclipse guys to fix their code, and to make sure they set this variable as a workaround until then in their own distribution. Ubuntu doesn&#8217;t have any influence on that.
</p></blockquote>
<p>And now for solving this problem is quite simple, you just enter this command in terminal before execute eclipse, </p>
<pre class="brush: bash;">
export GDK_NATIVE_WINDOWS=true
</pre>
<p>This solution is working in my box, if you don&#8217;t wanna execute this command in every launcing eclipse, you can add this line into .bashrc line, so whenever you launch terminal, it will automatically executed. Now i can enjoy working with cute koala. </p>
<p>Happy Coding <img src='http://s0.wp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/singgihpraditya.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/singgihpraditya.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/singgihpraditya.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/singgihpraditya.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/singgihpraditya.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/singgihpraditya.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/singgihpraditya.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/singgihpraditya.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/singgihpraditya.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/singgihpraditya.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/singgihpraditya.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/singgihpraditya.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/singgihpraditya.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/singgihpraditya.wordpress.com/74/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=singgihpraditya.wordpress.com&amp;blog=2270691&amp;post=74&amp;subd=singgihpraditya&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://singgihpraditya.wordpress.com/2009/11/04/solving-eclipse-galileo-problem-in-karmic-koala-ubuntu-9-10/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bf2e570e92acba054ae63f3484167850?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">adit</media:title>
		</media:content>
	</item>
		<item>
		<title>Simple Maven2, Spring 2.5, JPA and Hibernate integration</title>
		<link>http://singgihpraditya.wordpress.com/2009/03/19/simple-maven2-spring-25-jpa-and-hibernate-integration/</link>
		<comments>http://singgihpraditya.wordpress.com/2009/03/19/simple-maven2-spring-25-jpa-and-hibernate-integration/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 02:12:46 +0000</pubDate>
		<dc:creator>singgihpraditya</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://singgihpraditya.wordpress.com/?p=45</guid>
		<description><![CDATA[A few months ago, i&#8217;ve read a tutorial about spring 2.5 writen by Endy Muhardin (one of JUG Indonesia Hall Of Fame), that tutorial explained bout newest features of Spring 2.5, this version now supports Annotation. Configuration is no longer always in xml file. this made our effort to build program pragmatically  more easier to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=singgihpraditya.wordpress.com&amp;blog=2270691&amp;post=45&amp;subd=singgihpraditya&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A few months ago, i&#8217;ve read a <a title="tutorial" href="http://endy.artivisi.com/blog/java/akses-database-spring25/" target="_blank">tutorial</a> about spring 2.5 writen by Endy Muhardin (one of JUG Indonesia Hall Of Fame), that tutorial explained bout newest features of Spring 2.5, this version now supports Annotation. Configuration is no longer always in xml file. this made our effort to build program pragmatically  more easier to configure, faster and efficient.</p>
<p>But due to my bustle, and a regulation in place i work now. i have to leave Spring Frameworks. My project prefer choosing EJB3 and Struts2 as main developtment stack. the main reason is our client need a distributable application (even i know that spring support those too). Besides, developt a  ORM for handling database using JPA is more interesting for me than other approach. One question is, how bout people who doesnt need EJB feature which needed heavy container like Glassfish or JBOSS to running their application?.</p>
<p>Fortunately, Spring support JPA for connecting  to database, we can choose Hibernate or Toplink for JPA implementations. and it&#8217;s still can run in light web server like tomcat or jetty.  i&#8217;ll give you very simple example using JPA+Hibernate in Spring 2.5.<span id="more-45"></span></p>
<p>I&#8217;m using apache-maven2 for build this program, you can download it <a href="http://maven.apache.org/download.html">here</a> and read <a href="http://www.jivesoftware.com/jivespace/docs/DOC-3528">this</a> tutorial for installation.</p>
<p>Let me assume you have using maven2 before. Because we using Hibernate-Annotation, we need create a POJO class references from our table in database.  All entity class must be registered with @Entity annotation. in Person class below i have added named query. it can be used if we want create costum query beside delete, update or persist (create) data.</p>
<pre class="brush: java;">
package org.thenest.simplespring.models;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(name = &quot;PERSON&quot;)
@NamedQueries( { @NamedQuery(name = &quot;Person.findAll&quot;, query = &quot;SELECT p FROM Person p&quot;) })
public class Person {
	private int id;
	private String name;
	private int age;

	public void setId(int id) {
		this.id = id;
	}

	@Id
	public int getId() {
		return id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public int getAge() {
		return age;
	}
}
</pre>
<p>And this is DDL file for create table PERSON (i&#8217;m using mysql), and insert data into thus table.</p>
<pre class="brush: sql;">
CREATE TABLE PERSON(
	ID INT(5) PRIMARY KEY NOT NULL AUTO_INCREMENT,
	NAME VARCHAR(50) NOT NULL,
	AGE INT(3) NOT NULL);

INSERT INTO PERSON values(NULL,'Michael','22');
INSERT INTO PERSON values(NULL,'Alex','23');
INSERT INTO PERSON values(NULL,'Kevin','19');
</pre>
<p>One DAO class interface and it&#8217;s implementations. we can notice that PersonServiceJpa class have @Repository annotation. it&#8217;s mean we doesn&#8217;t needed to register this DAO class in Spring&#8217;s application context. We gonna make all DAO auto scanned.</p>
<pre class="brush: java;">
package org.thenest.simplespring.services;

import java.util.List;

import org.thenest.simplespring.models.Person;

public interface IPersonService {
	public boolean save(Person person);
	public List&lt;Person&gt; getAll();
	public Person getById(int id);
	public boolean delete(Person person);
	public boolean update(Person person);
}
</pre>
<pre class="brush: java;">
package org.thenest.simplespring.services.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.thenest.simplespring.models.Person;
import org.thenest.simplespring.services.IPersonService;

@Repository(&quot;iPersonService&quot;)
@Transactional(readOnly = true)
public class PersonServiceJpa implements IPersonService {

	private EntityManager entityManager;

	@PersistenceContext
	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}

	public EntityManager getEntityManager() {
		return entityManager;
	}

	@Override
	public Person getById(int id) {
		// TODO Auto-generated method stub
		return entityManager.find(Person.class, id);
	}

	public List&lt;Person&gt; getAll() {
		Query query = entityManager.createNamedQuery(&quot;Person.findAll&quot;);
		List&amp;amp;lt;Person&amp;amp;gt; persons = null;
		persons = query.getResultList();
		return persons;
	}

	@Override
	public boolean save(Person person) {
		entityManager.persist(person);
		entityManager.flush();
		return true;
	}

	@Override
	public boolean update(Person person) {
		entityManager.merge(person);
		entityManager.flush();
		return true;
	}

	@Override
	public boolean delete(Person person) {
		person = entityManager.getReference(Person.class, person.getId());
		if (person == null)
			return false;
		entityManager.remove(person);
		entityManager.flush();
		return true;
	}
}
</pre>
<p>And persistence.xml file :</p>
<pre class="brush: xml;">
&lt;persistence xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot;
		xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
		xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd&quot;
		version=&quot;1.0&quot;&gt;

	&lt;persistence-unit name=&quot;testa&quot; transaction-type=&quot;RESOURCE_LOCAL&quot;&gt;
        &lt;class&gt;org.thenest.simplespring.models.Person&lt;/class&gt;
    &lt;/persistence-unit&gt;
&lt;/persistence&gt;
</pre>
<p>Here they are application context, you need to change dataSource setting with your locat variable.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:p=&quot;http://www.springframework.org/schema/p&quot;
	xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot; xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
	xmlns:jee=&quot;http://www.springframework.org/schema/jee&quot; xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot;
	xsi:schemaLocation=&quot;
			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
			http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
			http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
			http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
			http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd&quot;&gt;

	&lt;context:annotation-config /&gt;
	&lt;context:component-scan base-package=&quot;org.thenest.simplespring.services&quot; /&gt;
	&lt;tx:annotation-driven /&gt;
	&lt;bean id=&quot;dataSource&quot;
		class=&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;
		p:driverClassName=&quot;com.mysql.jdbc.Driver&quot; p:url=&quot;jdbc:mysql://localhost/iseng&quot;
		p:username=&quot;root&quot; p:password=&quot;rahasia&quot; /&gt;
	&lt;bean id=&quot;entityManagerFactory&quot;
		class=&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot;
		p:dataSource-ref=&quot;dataSource&quot; p:jpaVendorAdapter-ref=&quot;jpaAdapter&quot;&gt;
		&lt;property name=&quot;loadTimeWeaver&quot;&gt;
			&lt;bean
				class=&quot;org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver&quot; /&gt;
		&lt;/property&gt;
	&lt;/bean&gt;
	&lt;bean id=&quot;transactionManager&quot; class=&quot;org.springframework.orm.jpa.JpaTransactionManager&quot;
		p:entityManagerFactory-ref=&quot;entityManagerFactory&quot; /&gt;
	&lt;bean id=&quot;jpaAdapter&quot;
		class=&quot;org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter&quot;
		p:database=&quot;MYSQL&quot; p:showSql=&quot;true&quot; /&gt;
&lt;/beans&gt;
</pre>
<p>Cause i&#8217;m using JUnit too for unit testing, this is unit testing class. i assume you have using JUnit too before.</p>
<pre class="brush: java;">
package test.org.thenest.simplespring;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.thenest.simplespring.models.Person;
import org.thenest.simplespring.services.IPersonService;

public class PersonDaoSpringJpaTest {

	private ApplicationContext ctx;
	private IPersonService personService;
	private Logger log = Logger.getLogger(this.getClass());

	public PersonDaoSpringJpaTest() {
		BasicConfigurator.configure();
		// TODO Auto-generated constructor stub
		ctx = new ClassPathXmlApplicationContext(&quot;applicationContext.xml&quot;);
		personService = (IPersonService) ctx.getBean(&quot;iPersonService&quot;);
		log.info(&quot;Application Context Loaded&quot;);
	}

	@Test
	public void testGetAll() {
		log.info(&quot;Test get all =================================&quot;);
		for (Person p : personService.getAll()) {
			log.info(&quot;Name : &quot; + p.getName() + &quot; Age &quot; + p.getAge());
		}
	}

	@Test
	public void testSave() {
		log.info(&quot;Test Save Data =================================&quot;);
		Person person = new Person();
		person.setName(&quot;Raven&quot;);
		person.setAge(23);
		personService.save(person);
	}

	@Test
	public void testGetDataById() {
		log.info(&quot;Test get data by id ==========================&quot;);
		Person p = personService.getById(1);
		log.info(&quot;Name : &quot; + p.getName() + &quot; Age &quot; + p.getAge());

	}

	@Test
	public void testUpdateData() {
		log.info(&quot;Test update data =============================&quot;);
		Person p = personService.getById(1);
		log.info(&quot;Name : &quot; + p.getName() + &quot; Age &quot; + p.getAge());
		p.setAge(30);
		personService.update(p);

	}

	@Test
	public void testDeleteData() {
		log.info(&quot;Test delete all ==============================&quot;);
		Person p = personService.getById(1);
		personService.delete(p);

	}
}
</pre>
<p>And last, Maven 2 build file, pom.xml.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project&gt;
	&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
	&lt;groupId&gt;SimpleSpringJpaHibernateApp&lt;/groupId&gt;
	&lt;artifactId&gt;SimpleSpringJpaHibernateApp&lt;/artifactId&gt;
	&lt;packaging&gt;jar&lt;/packaging&gt;
	&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
	&lt;description&gt;&lt;/description&gt;
	&lt;build&gt;
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
				&lt;configuration&gt;
					&lt;executable&gt;${JAVA_HOME}/bin/javac
					&lt;/executable&gt;
					&lt;compilerVersion&gt;1.6&lt;/compilerVersion&gt;
					&lt;source&gt;1.6&lt;/source&gt;
					&lt;target&gt;1.6&lt;/target&gt;
					&lt;debug&gt;true&lt;/debug&gt;
					&lt;fork&gt;true&lt;/fork&gt;
					&lt;showWarnings&gt;true&lt;/showWarnings&gt;
					&lt;showDeprecation&gt;true&lt;/showDeprecation&gt;
				&lt;/configuration&gt;
			&lt;/plugin&gt;
		&lt;/plugins&gt;
	&lt;/build&gt;
	&lt;dependencies&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;log4j&lt;/groupId&gt;
			&lt;artifactId&gt;log4j&lt;/artifactId&gt;
			&lt;version&gt;1.2.9&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework&lt;/groupId&gt;
			&lt;artifactId&gt;spring&lt;/artifactId&gt;
			&lt;version&gt;2.5.4&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework&lt;/groupId&gt;
			&lt;artifactId&gt;spring-test&lt;/artifactId&gt;
			&lt;version&gt;2.5.5&lt;/version&gt;
			&lt;scope&gt;test&lt;/scope&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;javax.persistence&lt;/groupId&gt;
			&lt;artifactId&gt;persistence-api&lt;/artifactId&gt;
			&lt;version&gt;1.0&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;hsqldb&lt;/groupId&gt;
			&lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
			&lt;version&gt;1.8.0.7&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
			&lt;artifactId&gt;hibernate-entitymanager
			&lt;/artifactId&gt;
			&lt;version&gt;3.3.2.GA&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;commons-lang&lt;/groupId&gt;
			&lt;artifactId&gt;commons-lang&lt;/artifactId&gt;
			&lt;version&gt;2.4&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;commons-collections&lt;/groupId&gt;
			&lt;artifactId&gt;commons-collections&lt;/artifactId&gt;
			&lt;version&gt;3.2&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;mysql&lt;/groupId&gt;
			&lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
			&lt;version&gt;5.1.6&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;junit&lt;/groupId&gt;
			&lt;artifactId&gt;junit&lt;/artifactId&gt;
			&lt;version&gt;4.2&lt;/version&gt;
		&lt;/dependency&gt;
	&lt;/dependencies&gt;
&lt;/project&gt;
</pre>
<p>You can download all complete code <a href="http://singgihpraditya.googlepages.com/SimpleSpringJpaHibernateApp.zip">here</a> . If you wan&#8217;t to integrating Spring without JPA bridge, I&#8217;ve already short tutorial about Spring 3.0 and Hibernate <a href="http://singgihpraditya.googlepages.com/SimpleSpringJpaHibernateApp.zip">here<br />
</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/singgihpraditya.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/singgihpraditya.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/singgihpraditya.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/singgihpraditya.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/singgihpraditya.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/singgihpraditya.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/singgihpraditya.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/singgihpraditya.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/singgihpraditya.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/singgihpraditya.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/singgihpraditya.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/singgihpraditya.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/singgihpraditya.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/singgihpraditya.wordpress.com/45/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=singgihpraditya.wordpress.com&amp;blog=2270691&amp;post=45&amp;subd=singgihpraditya&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://singgihpraditya.wordpress.com/2009/03/19/simple-maven2-spring-25-jpa-and-hibernate-integration/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bf2e570e92acba054ae63f3484167850?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">adit</media:title>
		</media:content>
	</item>
	</channel>
</rss>
