aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate without J2EE server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate without J2EE server" Watch "Hibernate without J2EE server" New topic
Author

Hibernate without J2EE server

Marcelo Chong
Greenhorn

Joined: Apr 23, 2005
Posts: 2
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 !!!
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Marcelo Chong
Greenhorn

Joined: Apr 23, 2005
Posts: 2
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?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


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)


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
scott powell
Greenhorn

Joined: May 11, 2005
Posts: 1
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?
inwish tandon
Greenhorn

Joined: Apr 06, 2005
Posts: 8
try this ,,
put your table.hbm.xml in the classes folder ., in the corresponding package.
lisa klag
Greenhorn

Joined: Apr 02, 2004
Posts: 2
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate without J2EE server