Category Archives: hibernate

Configure Hibernate for Jdeveloper

Here is the way to configure hibernate to work on JDeveloper

First thing first

As you know the three main things in setting up any hibernate is to have

  • Reference to hibernate3.jar library in classpath
  • Having hibernate.cfg.xml file (can be done programmatic way as well)
  • The mapping file (eg. Simple.hbm.xml)

To make this work for JDeveloper, download the latest version of hibernate3

Refer the downloaded location in the projects library and classpath by Adding a Library(Add Library)  – Create New – Add Entry

Provide the Library Name as ‘Hibernate’ (can be of your choice) and add the following libraries

  • hibernate3.jar
  • antlr-2.7.6.jar
  • commons-collections-3.1.jar
  • dom4j-1.6.1.jar
  • javassist-3.4.GA.jar
  • jta-1.1.jar
  • slf4j-api-1.5.2.jar

Have the hibernate.cfg.xml file in your current working directory

<?xml version='1.0' encoding='utf-8'?>

<!--<span class="hiddenSpellError" pre=""-->DOCTYPE hibernate-configuration PUBLIC

"-//Hibernate/Hibernate Configuration DTD 3.0//EN"




<!-- Database connection settings -->





<property name="connection.username">system</property>

<property name="connection.password">fusion</property>

<!-- <span class="hiddenSpellError" pre="">JDBC</span> connection pool (use the built-in) -->

<property name="connection.pool_size">1</property>

<!-- SQL dialect -->



<!-- Enable Hibernate's automatic session context management




<!-- Disable the second-level cache -->




<!-- Echo all executed SQL to <span class="hiddenSpellError" pre="to ">stdout</span> -->

<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->

<property name="">create</property>

<mapping resource="Simple.hbm.xml"/>



The configuration file is for Oracle driver.. this can be changed





<property name="connection.username">system</property>

<property name="connection.password">fusion</property>

You have to specify the mapping file also

<mapping resource="Simple.hbm.xml"/>

the highlighted libraries are added from slf4j to overcome

As the final step, represent the db table of yours as a simple pojo class ( like

public class Simple {

private Long id;

private String title;

private Date date;

public Simple() {}

public Long getId() {

return id;


private void setId(Long id) { = id;


public Date getDate() {

return date;


public void setDate(Date date) { = date;


public String getTitle() {

return title;


public void setTitle(String title) {

this.title = title;


private Set participants = new HashSet();

public Set getParticipants() {

return participants;


public void setParticipants(Set participants) {

this.participants = participants;



where id, title and date represents the column name of the table in the db

Have a corresponding mapping file in the same qualified path (Simple.hbm.xml)

<?xml version="1.0"?>

<!--<span class="hiddenSpellError" pre=""-->DOCTYPE hibernate-mapping PUBLIC

"-//Hibernate/Hibernate Mapping DTD 3.0//EN"



<class table="EVENTS">

<id name="id" column="EVENT_ID">



<property name="date" column="EVENT_DATE"/>

<property name="title"/>



Have a where you instantiate the Configuration, Session and get involved in the transaction

import org.hibernate.Session;

import org.hibernate.SessionFactory;

import org.hibernate.cfg.Configuration;

public class ConfigFile {

static Session session;

public ConfigFile() {



public static void main(String[] args){

Configuration cfg = new Configuration().configure();

SessionFactory sessions = cfg.buildSessionFactory();

Session sess = sessions.openSession();

session = sess;

Simple s = new Simple();




Run the that’s it. 🙂