-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Exception in thread main.
PostPosted: Thu Apr 20, 2006 7:07 am 
Newbie

Joined: Tue Apr 11, 2006 9:06 am
Posts: 10
Hi,

I am new to Hibernate and my prog is simple deletion from the db.
Hibernate vertionis 3.1
my DB is mysql

My Question is, can i do the deletion without using any getter and setter method? I gave my id value wihtin the same prog. where i create the session using a variable.

Eventmanager.java
----------------------------
package events;
import org.hibernate.Session;

import java.util.Date;
import java.util.*;

import util.HibernateUtil;

public class EventManager
{

public static void main(String[] args)
{
EventManager mgr = new EventManager();

if (args[0].equals("delete"))
{
mgr.createAndStoreEvent(1);

}


HibernateUtil.getSessionFactory().close();
}

private void createAndStoreEvent(int id)
{

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

session.beginTransaction();
int EVENT_ID=id;
Event theEvent = (Event) session.get(Event.class, new Long(EVENT_ID));

session.delete(theEvent);

session.getTransaction().commit();
}


}

Event.java
--------------
package events;
import java.util.Date;

public class Event
{
private int id;
private Date date;
private String title;

public Event()
{}

public int getId() {
return id;
}

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


util\HibernateUtil.java
-------------------------------
package util;

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;
}

}

The Exception is:Exception in thread main
Initial SessionFactory crreation is failed.

Pls.... Help.

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.