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:
Code:
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"
My addpublisher.java code :
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:
Code:
<!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:
Code:
id: int auto_increment
name: varchar(100)
the publisher.hbm.xml:
Code:
<?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 ?
thanks !!![/code]