• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate without J2EE server

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am using database mysql4.1
IDE: eclispe

My Application Structure:
application -
-src
Publisher.java
Publisher.hbm.xml
-main
AddPublisher.java

hibernate.cfg.xml
log4j.properties

-lib
hibernate3.jar
all jars in hibernate/lib

When i run addpublisher, it comes error:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1137)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1161)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1148)
at Main.AddPublisher.main(AddPublisher.java:14)
Exception in thread "main"

My addpublisher.java code :
public static void main(String[] args){
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
Publisher publisher = new Publisher();
Transaction tx = session.beginTransaction();
publisher.setName("Prentice Hall");
session.saveOrUpdate(publisher);
tx.commit();
session.close();
}
}

my hibernate.cfg.xml:

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>


<session-factory>

<property name="show_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLMyISAMDialect</property>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/bookstore</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>

<mapping resource="POJO/publisher.hbm.xml"/>
</session-factory>
</hibernate-configuration>

My publisher schema in database:

id: int auto_increment
name: varchar(100)


the publisher.hbm.xml:

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

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="org.hibernate.bookstore.Publisher"
table="publisher"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="publisher"
</meta>

<id
name="id"
type="java.lang.Integer"
column="id"
>
<meta attribute="field-description">
@hibernate.id
generator-class="assigned"
type="java.lang.Integer"
column="id"

</meta>
<generator class="assigned" />
</id>

<property
name="name"
type="java.lang.String"
column="name"
not-null="true"
length="255"
>
<meta attribute="field-description">
@hibernate.property
column="name"
length="255"
not-null="true"
</meta>
</property>

<!-- Associations -->


</class>
</hibernate-mapping>




Can anyone help me how to solve it and make my program works?

thanks !!!
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like the error message says:

Originally posted by Marcelo Chong:
org.hibernate.HibernateException: /hibernate.cfg.xml not found


Hibernate can't find the configuration file, hibernate.cfg.xml, from the classpath. To fix this for Eclipse, go to your project's properties and add whatever folder hibernate.cfg.xml is located in to the project classpath.
 
Marcelo Chong
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Lasse Koskela,

After that, when i run the program, i got the following error:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
org.hibernate.MappingException: entity class not found: org.hibernate.bookstore.Publisher
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:87)
at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:160)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:42)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:107)
at org.hibernate.persister.entity.BasicEntityPersister.<init>(BasicEntityPersister.java:401)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:104)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:206)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1055)
at Main.AddPublisher.main(AddPublisher.java:14)
Caused by: java.lang.ClassNotFoundException: org.hibernate.bookstore.Publisher
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.mapping.PersistentClass.getMappedClass(PersistentClass.java:84)
... 9 more
Exception in thread "main"


What does it means and how can i fix it?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Caused by: java.lang.ClassNotFoundException: org.hibernate.bookstore.Publisher



You appear to be declaring a persistent class called org.hibernate.bookstore.Publisher in hibernate.cfg.xml which doesn't exist in the classpath. Make sure you are deploying this class file to the right place (i.e. where ever you are running your app as you would any normal class file)
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm getting the same problem, following the Cat example in the Hibernate 3.0 guide.

I'm using Eclipse. Hibernate, the JDBC driver, etc., are in the Eclipse build path.

The hibernate.cfg.xml file, my Cat.hbm.xml file and my Cat.java file are all in the same folder: src/com/rps/hibernate and compiles to the same folder bin/com/rps/hibernate.

The test application is in the same directory, too.

The Cat mapping starts like this:
<hibernate-mapping>
<class name="com.rps.hibernate.Cat" table="CAT">

My Java class starts like this:

package com.rps.hibernate;
public class Cat {

Any suggestions for what I might be doing wrong?
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this ,,
put your table.hbm.xml in the classes folder ., in the corresponding package.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having the same problem and I'm not getting past this. Can anyone offer some more ideas. I know this should be obvious...just wait until I have to make it work with ColdFusion.
thanks,
lisa

Originally posted by Marcelo Chong:
Thanks Lasse Koskela,

After that, when i run the program, i got the following error:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
org.hibernate.MappingException: entity class not found: org.hibernate.bookstore.Publisher
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:87)
at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:160)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:42)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:107)
at org.hibernate.persister.entity.BasicEntityPersister.<init>(BasicEntityPersister.java:401)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:104)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:206)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1055)
at Main.AddPublisher.main(AddPublisher.java:14)
Caused by: java.lang.ClassNotFoundException: org.hibernate.bookstore.Publisher
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.mapping.PersistentClass.getMappedClass(PersistentClass.java:84)
... 9 more
Exception in thread "main"


What does it means and how can i fix it?

 
reply
    Bookmark Topic Watch Topic
  • New Topic