-->
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.  [ 4 posts ] 
Author Message
 Post subject: need some help to get started
PostPosted: Tue Mar 30, 2004 9:31 am 
Newbie

Joined: Tue Mar 30, 2004 9:25 am
Posts: 2
I have to do a presentation about object persistence using Hibernate.

I downloaded the latest version, and I'm using MySQL as DBMS.

I can compile my classes, I've made a valid mapping and a properties file.

But when I try to run the application, he always says that he cannot find the hibernate.properties or hibernate.cfg.xml file. But they are there! I tried to put the files in every possible directory in my system's classpath, but he still gives this error.

What am I doing wrong??


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 9:33 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
We yet have to invent a magic device to remotely look at your source code. Did you see the big red warning before you posted?

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 9:44 am 
Newbie

Joined: Tue Mar 30, 2004 9:25 am
Posts: 2
My apologies...

Latest Hibernate version

java code:

Code:
package de.gloegl.road2hibernate;

import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.cfg.Configuration;

import java.text.DateFormat;
import java.util.Date;
import java.util.List;

public class EventManager {

   private SessionFactory sessionFactory;

   public EventManager() {
      try {
         System.out.println("Initializing Hibernate");
         sessionFactory = new Configuration().configure().buildSessionFactory();
         System.out.println("Finished Initializing Hibernate");
      } catch (HibernateException e) {
         e.printStackTrace();
      }
   }
   
   public static void main(String[] args) throws java.text.ParseException {
      EventManager instance = new EventManager();
      if (args[0].equals("store")) {
         String title = args[1];
         Date theDate = new Date();
         instance.store(title, theDate);
      } else if (args[0].equals("list")) {
         List events = instance.listEvents();
         for (int i = 0; i<events.size(); i++) {
            Event theEvent = (Event) events.get(i);
            System.out.println("Event " + theEvent.getTitle() + " Time: " + theEvent.getDate());
         }
      }
      System.exit(0);   
   }
   
   private List listEvents() {
      try {
         Session session = sessionFactory.openSession();
         Transaction tx = session.beginTransaction();
                  
         List result = session.find("from Event");
         
         tx.commit();
         session.close();
         
         return result;
      } catch (HibernateException e) {
         throw new RuntimeException(e.getMessage());
      }
   }      
   
   private void store(String title, Date theDate) {      
      try {
         Session session = sessionFactory.openSession();
         Transaction tx = session.beginTransaction();
         
         Event theEvent = new Event();
         theEvent.setTitle(title);
         theEvent.setDate(theDate);
         
         session.save(theEvent);
         
         tx.commit();
         session.close();
      } catch (HibernateException e) {
         e.printStackTrace();
      }
   }

}


INFO - Hibernate 2.1.2
INFO - hibernate.properties not found
INFO - using CGLIB reflection optimizer
INFO - configuring from resource: /hibernate.cfg.xml
INFO - Configuration resource: /hibernate.cfg.xml
WARN - /hibernate.cfg.xml not found
net.sf.hibernate.HibernateException: /hibernate.cfg.xml not found
at net.sf.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:831)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:855)
at de.gloegl.road2hibernate.EventManager.<init>(EventManager.java:20)
at de.gloegl.road2hibernate.EventManager.main(EventManager.java:28)

But both the files are in every directory of my build, source and libs...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 9:50 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This line

sessionFactory = new Configuration().configure().buildSessionFactory();

calls the classloader that loaded hibernate2.jar and asks him to load "/hibernate.cfg.xlm", thats all. You can try configure("/hibernate.cfg.xml"), but that should be the same. Can't do much about that.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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