-->
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.  [ 7 posts ] 
Author Message
 Post subject: Example from chapter II and Eclipse not working
PostPosted: Mon Jul 11, 2005 10:12 am 
This is very humbling….
I am new to Hibernate and am trying to get the example in chapter II working. I think that I have a simple problem but I can not get past it.. I have read through the FAQ and of course the manual but still no luck.. I am not using ANT instead using Eclipse for everything.

Here is my Event.hbm.xml and hibernate.cfg.xml files. But I think that they are fine.


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<generator class="increment"/>
</id>
<property name="date" type="timestamp" column="EVENT_DATE"/>
<property name="title"/>
</class>

</hibernate-mapping>



================


<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>

<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:data/tutorial</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping resource="Event.hbm.xml"/>
</session-factory>

</hibernate-configuration>

I think that hibernate uses some other mechanism to find and load the Event class. I just do not know how to set this up. Sorry I am just stuck.. Surly someone out there knows the answer to this simple question..

Thanks for you help
ray

Stack Trace:
09:14:32,626 INFO Environment:464 - Hibernate 3.0.5
09:14:32,626 INFO Environment:477 - hibernate.properties not found
09:14:32,626 INFO Environment:510 - using CGLIB reflection optimizer
09:14:32,642 INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling
09:14:32,705 INFO Configuration:1110 - configuring from resource: /hibernate.cfg.xml
09:14:32,705 INFO Configuration:1081 - Configuration resource: /hibernate.cfg.xml
09:14:32,986 DEBUG DTDEntityResolver:42 - trying to locate http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath under org/hibernate/
09:14:32,986 DEBUG DTDEntityResolver:53 - found http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath
09:14:33,033 DEBUG Configuration:1067 - connection.driver_class=org.hsqldb.jdbcDriver
09:14:33,033 DEBUG Configuration:1067 - connection.url=jdbc:hsqldb:data/tutorial
09:14:33,033 DEBUG Configuration:1067 - connection.username=sa
09:14:33,033 DEBUG Configuration:1067 - connection.password=
09:14:33,033 DEBUG Configuration:1067 - connection.pool_size=1
09:14:33,033 DEBUG Configuration:1067 - dialect=org.hibernate.dialect.HSQLDialect
09:14:33,033 DEBUG Configuration:1067 - show_sql=true
09:14:33,033 DEBUG Configuration:1067 - hbm2ddl.auto=create
09:14:33,033 DEBUG Configuration:1262 - null<-org.dom4j.tree.DefaultAttribute@a97b0b [Attribute: name resource value "Event.hbm.xml"]
09:14:33,033 INFO Configuration:444 - Mapping resource: Event.hbm.xml
09:14:33,048 DEBUG DTDEntityResolver:42 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath under org/hibernate/
09:14:33,048 DEBUG DTDEntityResolver:53 - found http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath
09:14:33,173 INFO HbmBinder:260 - Mapping class: Event -> EVENTS
09:14:33,204 ERROR Configuration:365 - Could not compile the mapping document
org.hibernate.MappingException: class Event not found while looking for property: id
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:81)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:275)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:360)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:294)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:236)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:152)
at org.hibernate.cfg.Configuration.add(Configuration.java:362)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:400)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:449)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1263)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1235)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1112)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1098)
at src.HibernateUtil.<clinit>(HibernateUtil.java:10)
at src.EventManager.createAndStoreEvent(EventManager.java:19)
at src.EventManager.main(EventManager.java:12)
Caused by: java.lang.ClassNotFoundException: Event
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:77)
... 17 more
Initial SessionFactory creation failed.org.hibernate.MappingException: Error reading resource: Event.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at src.HibernateUtil.<clinit>(HibernateUtil.java:14)
at src.EventManager.createAndStoreEvent(EventManager.java:19)
at src.EventManager.main(EventManager.java:12)
Caused by: org.hibernate.MappingException: Error reading resource: Event.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:452)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1263)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1235)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1112)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1098)
at src.HibernateUtil.<clinit>(HibernateUtil.java:10)
... 2 more
Caused by: org.hibernate.MappingException: class Event not found while looking for property: id
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:81)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:275)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:360)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:294)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:236)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:152)
at org.hibernate.cfg.Configuration.add(Configuration.java:362)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:400)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:449)
... 9 more
Caused by: java.lang.ClassNotFoundException: Event
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:77)
... 17 more


Top
  
 
 Post subject:
PostPosted: Mon Jul 11, 2005 11:14 am 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
Are you sure that you don't have Event in some other package? Could you post the Java code you are using please?

Code:
[Hint: If you use the "code" tags your XML and Java will be formatted much more nicely.]


Top
 Profile  
 
 Post subject: JDL THANKS FOR HELPING ME OUT
PostPosted: Mon Jul 11, 2005 11:46 am 
Okay, you asked for this.. Ha ha.. No man. seriously thanks for helping me out.. It is something simple but I just don't know enough about this stuff to figure it out.. Once I get something working I can go crazy and do all kinds of cool things but getting that first thing going is always hard..

Here is my directory structure:
[hibernate]
Under that I have
[data] : chapter II told me to create this in section 2.2.3
[lib] : where I placed all of the jar files from hibernate. Chapter II requested some of these but I put them all in there. In addition I also placed the JDBC driver for HSQL DB the database that Chapter II refers too.
[src] : this is where all of my source code and class file live along with my two hibernate config files hibernate.hbm.xml, Event.hbm.xml and log4j.properties. I will include the source for them later. The [src] directory also has a data directory inside of it. Inside the [src] directory I have Event.java, EventManager.java and HibernateUtil.java, as instructed by Chapter II.

Please note that hibernate.hbm.xml, and Event.hbm.xml are also at my root directory (inside the [hibernate] directory). Was not real sure where to place them and put them in both places as part of my debugging efforts.. I was going to get rid of the unused one later, once I figured this stuff out.

Strange things:
* I never was told to actually create a table in the HSQL DB database? how is that suppose to work.. Hibernate can do that, can it?
* Is the <property name = “connection.url”> jdbc:hsqlbd:data/tutorial</property>
correct? I created a tutorial directory under the data directory thinking that this might help me.. It did not..

MY EVENT CODE
Code:
package src;

import java.util.Date;

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

   public Event() {
      
   }
   public Long getId() {
      return id;
   }
   private void setId(Long id) {
      this.id = id;
   }
   public Date getDate() {
      return date;
   }
   public void setDate(Date date) {
      this.date = date;
   }
   public String getTitle() {
      return title;
   }
   public void setTitle(String title) {
      this.title = title;
   }
}




MY EVENTMANAGER CODE
Code:
package src;

import org.hibernate.Transaction;
import org.hibernate.Session;
import java.util.Date;


public class EventManager {
   public static void main(String[] args) {
      EventManager mgr = new EventManager();
      //if (args[0].equals("store")) {
         mgr.createAndStoreEvent("My Event", new Date());
      //}
      HibernateUtil.sessionFactory.close();
   }
   
   
   private void createAndStoreEvent(String title, Date theDate) {
      Session session = HibernateUtil.currentSession();
      Transaction tx = session.beginTransaction();
      Event theEvent = new Event();
      theEvent.setTitle(title);
      theEvent.setDate(theDate);
      session.save(theEvent);
      tx.commit();
      HibernateUtil.closeSession();
   }   
}


MY HIBERNATEUTIL.JAVA
Code:
package src;
import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil {
   public 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 final ThreadLocal session = new ThreadLocal();
   public static Session currentSession() throws HibernateException {
      Session s = (Session) session.get();
      // Open a new Session, if this thread has none yet
      if (s == null) {
         s = sessionFactory.openSession();
         // Store it in the ThreadLocal variable
         session.set(s);
      }
      return s;
   }
   public static void closeSession() throws HibernateException {
      Session s = (Session) session.get();
      if (s != null) {
         s.close();
      }
      session.set(null);
   }
}


Event.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

   <class name="Event" table="EVENTS">
        <id name="id" column="EVENT_ID">
           <generator class="increment"/>
        </id>
      <property name="date" type="timestamp" column="EVENT_DATE"/>
      <property name="title"/>
   </class>
   
</hibernate-mapping>



hibernate.cfg.xml
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>

<session-factory>
   <!-- Database connection settings -->
   <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
   <property name="connection.url">jdbc:hsqldb:data/tutorial</property>
   <property name="connection.username">sa</property>
   <property name="connection.password"></property>
   <!-- JDBC connection pool (use the built-in) -->
   <property name="connection.pool_size">1</property>
   <!-- SQL dialect -->
   <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
   <!-- Echo all executed SQL to stdout -->
   <property name="show_sql">true</property>
   <!-- Drop and re-create the database schema on startup -->
   <property name="hbm2ddl.auto">create</property>
   <mapping resource="Event.hbm.xml"/>
</session-factory>

</hibernate-configuration>


Top
  
 
 Post subject:
PostPosted: Mon Jul 11, 2005 2:43 pm 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
Code:
<class name="Event" table="EVENTS">


Your class is really "src.Event" since that's the package you're using.

Rather than changing that, however, I'd suggest fixing your project properties in Eclipse, since it's doubtful that you really want "src" to be your package.

Right click your project and choose Properties. Choose Java Build Path. Under the Source tab click Add and add your src directory. What this does is tell Eclipse that that directory is a container for your top level default package, rather than being part of the package itself. (Choose "yes" for any questions involving rebuilding your project or moving compiled code to the /bin directory.)


Top
 Profile  
 
 Post subject: Oh Man....
PostPosted: Mon Jul 11, 2005 3:10 pm 
Oh MAN.. That was it.. I was only following the instructions and that is what killed me.. See the instructions are for ANT and I did not want to use ant.. No offense to the Ant guys. It is a cool product, no question on that. And I have used it a lot.. I knew that it was something small. See normally I put my driver classes in the default package and then everything else under that. So I am not use to setting things up this way. I feel silly about this..

Well no red ink in the output. Don’t know what all this means yet but it is not RED so I am happy.. So I will dig through all of this new data I have..

Hey one last favor I want to ask you for.. Send me your contact info. I want to send you something. Listen you just got me out of an ugly place and I want you to have a little something on the side. I have been out of work for about 2 years, I just started here last week, and this is my first assignment here. I was failing, until you got involved and helped me out.. Honor me with this last request. Let me send you something. You did this for me, let me do something for you. I know that my request is off the wall but I want to thank you.

I just did not see this solution.. Now just by your answer I understand much more of this stuff.. I use to use hibernate a long time ago back in the beta days but have not looked at it for over 2 or 3 years.. I just needed to get something to work, something that I can build from.. Man, thanks..


Top
  
 
 Post subject:
PostPosted: Mon Jul 11, 2005 3:21 pm 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
The "thank you" you gave is plenty. If you really want to give something back, learn Hibernate and answer some other new user's question in the future.

Glad to hear that it's working for you now.


Top
 Profile  
 
 Post subject: well..
PostPosted: Mon Jul 11, 2005 3:27 pm 
hum.. Well I am, have no choice, going to learn this stuff like the back of my hand. I have to since I am planning on it being part of our next product.
I really wanted to send you something. but if this is what you would like then that is what I will do. I will honor your request and "pay it forward". I will do that for you.
ray


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