Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Object Relational Mapping and the fly likes why not ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "why not ?" Watch "why not ?" New topic

why not ?

Nanda Suraj

Joined: May 04, 2005
Posts: 8
Hi ,

I am a newbie to hibernate. I desperately need to sort a simple example.

I am using oracle as a database. I am trying to work out the example (Event) specified in I cleared of exceptions or errors. But the values giver is not inserting into the table.

The hbm.xml file I wrote is as :

<class name="events.Event" table="EVENTS">
<id name="id" column="EVENT_ID" type="integer" unsaved-value="0">
<generator class="increment"/>
<property name="dt" type="timestamp" column="EVENT_DATE"/>
<property name="title" column="TITLE"/>

and the class that does the transactions is :

* Created on 12 January 2006, 10:33

package events;

import org.hibernate.Session;

import java.util.Date;
import java.util.List;
import util.HibernateUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class EventManager {
private static Log log = LogFactory.getLog(HibernateUtil.class);
public static void main(String[] args) {

EventManager mgr = new EventManager();
long id = 101;
Event eve = new Event();
System.out.println("INSIDE LIST... ");
if (args[0].equals("store")) {

mgr.createAndStoreEvent("My Event", new Date());
else if (args[0].equals("list")) {
List events = mgr.listEvents();
for (int i = 0; i < events.size(); i++) {
Event theEvent = (Event) events.get(i);
System.out.println("Event: " + theEvent.getTitle() +
" Time: " + theEvent.getDt());

private void createAndStoreEvent(String title, Date theDate) {
try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();

Event theEvent = new Event();

System.out.println("event id : "+theEvent.getId());
System.out.println("event title : "+theEvent.getTitle());

}catch(Exception e){}

private List listEvents() {

Session session = HibernateUtil.getSessionFactory().getCurrentSession();


List result = session.createQuery("from Event").list();


return result;


Anybody have an idea why the values not storing into ?

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Possibly if you didn't ignore exceptions like this:then you might have an idea. At least print the stack trace when an exception occurs:
Nanda Suraj

Joined: May 04, 2005
Posts: 8
Yes, you are correct. When I printed the exception I got :
" identifier of an instance of events.Event was altered from 1 to 1 "

I don't understand why this exception occures ?

Please help me ..

Nanda Suraj

Joined: May 04, 2005
Posts: 8
I got it right. Thanks for the help.

I gave wrong type in the hbm.xml file. Instead of long , i gave integer.

Not its working and stored in the table.
I agree. Here's the link:
subject: why not ?
It's not a secret anymore!