Archive for Januari 27th, 2008
Tutorial : First Step To Hibernate Part 3
I can wait forever, if you say you’ll be there, too
I can wait forever, if you will, I know it’s worth it all
To spend my life alone with you.
- I can wait forever, Air Supply
Setelah dua tutorial yang cukup melelahkan (alah). Mari kita selesaikan trilogi ini hehehe.
Buat file hibernate.cfg.xml pada direktori WEB-INF/classes.
buat XML lagi temen tmen. File ini menunjukkan URL, username dan password database. XMl ini juga mengatur konfigurasi global dari hibernate.
< ?xml version='1.0' encoding='utf-8'?> < !DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate -configuration> <session -factory> <!-- Database connection settings --> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url"> jdbc:mysql://localhost/hibernate</property> <property name="connection.username">root</property> <property name="connection.password"></property> <!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property> <!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">thread</property> <!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">create</property> <mapping resource="beans/Mahasiswa.hbm.xml"/> </session> </hibernate>
Untuk panduan lengkap mengenai konfigurasi hibernate ini, anda dapat membaca dokumentasi resmi hibernate. Itu JAUH lebih lengkap(: P ). Lanjut ke langkah selanjutnya.
10 comments Januari 27, 2008
Tutorial : First Step To Hibernate Part 2
Biarkan aku menjaga perasaan ini
menjaga segenap cinta yang telah kau beri
engkau pergi aku takkan pergi
kau menjauh aku takkan jauh
sebenarnya diriku masih mengharapkanmu
- Menjaga Hati, Yovie Nuno
Setelah membuat class mahasiswa pada tutorial sebelumnya. Sekarang kita akan mulai membuat HibernateUtil, Servlet dan file xml konfigurasi.
Buat class HibernateUtil
Class ini hanya berisi inisialisasi awal hibernate session. Digunakan untuk mempermudah saja.
package beans;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
5 comments Januari 27, 2008
Tutorial : First Step To Hibernate Part 1
What’s the worst that I can say?
Things are better if I stay
So long and goodnight
So long and goodnight
- Helena, My Chemical Romance
Hi Folks!! Akhirnya bisa posting tutorial lagi. 3 hari ini sukses menambah persenjataan JAVA. Stack yang saya persenjatai adalah Data Access Layer. Dan yang terpilih untuk saya pelajari adalah HIBERNATE.

Apaan seh hibernate itu?. Berikut cuplikan dari wiki pedia.
Hibernate is an object-relational mapping (ORM) library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database. Hibernate solves Object-Relational impedance mismatch problems by replacing direct persistence-related database accesses with high-level object handling functions.
Sementara ini, klo menurut saya sih Hibernate tuh framework bwat memudahkan dalam mengakses dan memanipulasi data atau koneksi ke database.
Java menganut prinsip OOP, Dimana setiap permaslahan direpresentasikan dalam bentuk Objek misal (Mahasiswa, Nilai, DaftarHadir, Kelas) . Sedangkan database kebanyakan menganut prinsip relasional. Data disimpan dalam bentuk tabel. Untuk mempermudah komunikasi antara keduanya, diperlukan pihak ketiga ato jembatan suapaya Object bisa disimpan ke database dengan MUDAH dan SIMPLE. Jembatannya adalah Object Relational Mapping(ORM). Hibernate adalah salah satu framework ORM tadi. Yang lainnya ada Ibatis ma Oracle Toplink.
3 comments Januari 27, 2008



