-->
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.  [ 2 posts ] 
Author Message
 Post subject: Exception in thread main.
PostPosted: Thu Apr 20, 2006 6:57 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  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 5:54 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Cicilin wrote:
My Question is, can i do the deletion without using any getter and setter method?

Aren't you already doing the delete without any get or set methods? Load the objet then call session.delete on it.. no get or set..

Your exception is to do with creating the session factory, not deleting. In order for us to diagnose it, you'll have to post the exception, and all its nested exceptions. Please post them using code tags (code button above the edit window).


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

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.