-->
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: Resource: Cat.hbm.xml not found
PostPosted: Tue May 24, 2005 2:24 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 7:39 am
Posts: 27
Location: Rome, Italy
i'm running the example of the Cat included in hibernate reference, but i had problems with HibernateUtil.java, so i decided to include a small main() in HibernateUtil to quickly discover the problems. the class reads as follows, and it's simply the class suggested in the hibernate reference with a main() added that opens and closes the session:

Code:
import org.hibernate.*;
import org.hibernate.cfg.*;
import org.apache.commons.logging.*;


public class HibernateUtil {
   
    private static Log log = LogFactory.getLog(HibernateUtil.class);
   
    private static final SessionFactory sessionFactory;
   
    static {
        try {
        // Create the SessionFactory
            sessionFactory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
                log.error("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();
        session.set(s);
     }
    return s;
}
   
   

    public static void closeSession() throws HibernateException {
       
        Session s = (Session) session.get();
        session.set(null);
        if (s != null)
            s.close();
}
   
   
    public static void main(String[] args) {
       
        Session session = HibernateUtil.currentSession();
       
        HibernateUtil.closeSession();

    }

}





Hibernate version:
3.0
Mapping documents:
Cat.hbm.xml, placed in the same directory as Cat.java (\jakarta-tomcat-5.0.28\webapps\quickstart\quickstart\src\net\sf\hibernate\examples\quickstart)

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

<hibernate-mapping>
<class name="net.sf.hibernate.examples.quickstart.Cat" table="CAT">

   <!-- A 32 hex character is our surrogate key. It's automatically
      generated by Hibernate with the UUID pattern. -->
   <id name="id" type="string" unsaved-value="null" >
      <column name="CAT_ID" sql-type="char(32)" not-null="true"/>
      <generator class="uuid.hex"/>
   </id>

<!-- A cat has to have a name, but it shouldn' be too long. -->
   <property name="name">
      <column name="NAME" length="16" not-null="true"/>
   </property>

   <property name="sex"/>

   <property name="weight"/>
</class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
compile-single:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
java.lang.ExceptionInInitializerError
at HibernateUtil.<clinit>(HibernateUtil.java:30)
Caused by: org.hibernate.MappingException: Resource: Cat.hbm.xml not found
at org.hibernate.cfg.Configuration.addResource(Configuration.java:444)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1313)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1285)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1267)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1234)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1162)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1148)
at HibernateUtil.<clinit>(HibernateUtil.java:27)


Name and version of the database you are using:
mysql 4.1

it seems like i have not initialized the log4j system properly, but i cannot guess why....


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 4:52 pm 
Newbie

Joined: Fri May 20, 2005 12:39 pm
Posts: 10
Log4J is just warning you that no configuration was specified. The real problem is the location of the Cat.hbm.xml doesn't match what you specified in hibernate.cfg.xml. My guess is your configuration file looks like...

<!-- Mapping files -->
<mapping resource="Cat.hbm.xml"/>

In this case, move Cat.hbm.xml to the default package (...\src\). Or you can specify the path as follows...

<mapping resource="net/sf/hibernate/examples/quickstart/Cat.hbm.xml"/>

I prefer the latter approach as it keeps the mapping files in close proximity to the classes.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 6:29 am 
Beginner
Beginner

Joined: Tue May 17, 2005 7:39 am
Posts: 27
Location: Rome, Italy
yess yes yes!!!
now it works!!!

i should have guessed that the mapping resource should have had the same name of the class name specified in cat.hbm.xml...

(still have to solve some jdbc/datasource problems)


thanx so much for the help!


Top
 Profile  
 
 Post subject: Re: Resource: Cat.hbm.xml not found
PostPosted: Mon Apr 02, 2012 3:08 am 
Newbie

Joined: Mon Apr 02, 2012 3:05 am
Posts: 1
Cat is the route most cat entrepreneurs will select there may be circumstances where another choice is required. In these exclusive situations such as continual bladder attacks many cat entrepreneurs are optioning for organic substitute UTI therapies such as homeopathy.

vetoryl for dogs


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.