-->
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.  [ 3 posts ] 
Author Message
 Post subject: I getting fatal error
PostPosted: Thu Jun 09, 2005 7:20 am 
Beginner
Beginner

Joined: Thu Jun 09, 2005 3:18 am
Posts: 34
Location: India
java.lang.NoClassDefFoundError: org/dom4j/Attribute
at honey.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:38)
at honey.TestClient.createHoney(TestClient.java:43)
at honey.TestClient.main(TestClient.java:28)
Exception in thread "main"





public class TestClient {

public static void main(String[] args) {
Integer primaryKey = createHoney();
System.out.println("primary key is " + primaryKey);
updateHoney(primaryKey);
listHoney();
}
private static Integer createHoney() {
Session session = null;
Transaction tx = null;
Logger log = Logger.getLogger("TestClient");
log.info("creating honey");

Integer id = null;
System.out.println("Ok");
try {
// get the session from the factory
session = HibernateSessionFactory.currentSession();
// always start a transaction before doing something
// from the database
tx = session.beginTransaction();
// create a new object
Honey honey = new Honey();
honey.setName("Sebastian's favourite honey");
honey.setTaste("sweet");
// save it to the database, Hibernate returns your object
// with the primary key field updated!
id = (Integer) session.save(honey);
// commit your transaction or nothing is wrote to the db
tx.commit();
// clean up (close the session)
session.close();
} catch (HibernateException e) {
// when an error occured, try to rollback your
// transaction
if (tx != null)
try {
tx.rollback();
} catch (HibernateException e1) {
log.warn("rollback not successful");
}
/*
* close your session after an exception!! Your session
* is in an undefined and unstable situation so throw it away!
*
*/
if (session != null)
try {
session.close();
} catch (HibernateException e2) {
log.warn("session close not successful");
}
}
return id;
}
private static void updateHoney(Integer primaryKey) {
Session session = null;
Transaction tx = null;
Logger log = Logger.getLogger("TestClient");
log.info("updating honey");
try {
// get the session from the factory
session = HibernateSessionFactory.currentSession();
// always start a transaction before doing something
// (even reading) from the database
tx = session.beginTransaction();
// load object from the database
Honey honey = (Honey) session.get(Honey.class, primaryKey);
// honey is null when no object was found
if (honey != null) {
honey.setName("Sascha's favourite honey");
honey.setTaste("very sweet");
}
session.flush();
// commit your transaction or nothing is wrote to the db
tx.commit();
// clean up (close the session)
session.close();
} catch (HibernateException e) {
// when an error occured, try to rollback your
// transaction
if (tx != null)
try {
tx.rollback();
} catch (HibernateException e1) {
log.warn("rollback not successful");
}
/*
* close your session after an exception!! Your session
* is in an undefined and unstable situation so throw it away!
*
*/
if (session != null)
try {
session.close();
} catch (HibernateException e2) {
log.warn("session close not successful");
}
}
}
private static void listHoney() {
Session session = null;
Transaction tx = null;
Logger log = Logger.getLogger("TestClient");
log.info("listing honey");
try {
// get the session from the factory
session = HibernateSessionFactory.currentSession();
// always start a transaction before doing something
// (even reading) from the database
tx = session.beginTransaction();
List honeys = session.find("select from Honey");
for (Iterator iter = honeys.iterator(); iter.hasNext();) {
Honey honey = (Honey) iter.next();
System.out.println("Id " + honey.getId() + " Name "
+ honey.getName());
}
// commit your transaction or nothing is wrote to the db
tx.commit();
// clean up (close the session)
session.close();
} catch (HibernateException e) {
// when an error occured, try to rollback your
// transaction
if (tx != null)
try {
tx.rollback();
} catch (HibernateException e1) {
log.warn("rollback not successful");
}
/*
* close your session after an exception!! Your session
* is in an undefined and unstable situation so throw it away!
*
*/
if (session != null)
try {
session.close();
} catch (HibernateException e2) {
log.warn("session close not successful");
}
}
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 8:19 am 
Newbie

Joined: Fri May 20, 2005 2:42 am
Posts: 14
add the dom4j.jar to your classpath, and all the other jars that
are required (see README.txt in the jar directory of the hibernate
distribution)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 10:21 am 
Beginner
Beginner

Joined: Thu Jun 09, 2005 3:18 am
Posts: 34
Location: India
thanx max


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.