-->
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.  [ 6 posts ] 
Author Message
 Post subject: create MySql database error
PostPosted: Tue May 23, 2006 4:44 pm 
Newbie

Joined: Wed May 17, 2006 6:31 pm
Posts: 5
I don't know why i have a such error. I hope some expert can help me.

Hibernate version:3.2.0CR

Mapping documents:Customer.hbm.xml
<?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="Customer" table="CUSTOMER">
<id name="id" column="CID">
<generator class="increment" />
</id>
<property name="username" column="USERNAME" />
<property name="password" column="PASSWORD" />
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
try {
SessionFactory sf = new Configuration().addClass(Customer.class)
.setProperty(Environment.HBM2DDL_AUTO, "create")
.buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();

for (int i = 0; i < 200; i++) {
Customer customer = new Customer();
customer.setUsername("customer" + i);
customer.setPassword("customer");
session.save(customer);
}

tx.commit();


Full stack trace of any exception that occurs:
exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at Test.main(Test.java:9)



Name and version of the database you are using:
mySql 5.0


Last edited by junjun on Tue May 23, 2006 7:11 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 5:57 pm 
Regular
Regular

Joined: Mon May 22, 2006 2:30 pm
Posts: 74
It appears that you do not have one of the required jars in your classpath. There are a number of jars on which Hibernate depends at runtime. You are most likely missing dom4j-1.6.1.jar (HIbernate 3.1) which is located in the /lib folder in the Hibernate distribution. It also appears that there is something wrong with your mapping xml, since it was attempting to generate a Document Exception, but was unable to load the class to throw the exception. Add the jar so that you can see the specifics of the exception.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 7:09 pm 
Newbie

Joined: Wed May 17, 2006 6:31 pm
Posts: 5
hi,
It really helped. I do as you said, add serveral jar file, but i still have a error, i don't why, please help me. thank you!!
the following is the error:
Buildfile: D:\workspace\My1stHibernate\build.xml
init:
[mkdir] Created dir: D:\workspace\My1stHibernate\classes
build:
[javac] Compiling 2 source files to D:\workspace\My1stHibernate\classes
[copy] Copying 1 file to D:\workspace\My1stHibernate\classes
run:
[java] 2006-5-24 1:00:08 org.hibernate.cfg.Environment <clinit>
[java]information: Hibernate 3.1.3
[java] 2006-5-24 1:00:08 org.hibernate.cfg.Environment <clinit>
[java] information: hibernate.properties not found
[java] 2006-5-24 1:00:08 org.hibernate.cfg.Environment <clinit>
[java] informaiton: using CGLIB reflection optimizer
[java] 2006-5-24 1:00:08 org.hibernate.cfg.Environment <clinit>
[java] information: using JDK 1.4 java.sql.Timestamp handling
[java] 2006-5-24 1:00:08 org.hibernate.cfg.Configuration addClass
[java] information: Reading mappings from resource: Customer.hbm.xml
[java] 2006-5-24 1:00:09 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
[java] information: Mapping class: Customer -> CUSTOMER
[java] 2006-5-24 1:00:09 org.hibernate.connection.UserSuppliedConnectionProvider configure
[java] warning: No connection properties specified - the user must supply JDBC connections
[java] org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
[java] at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
[java] at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
[java] at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:378)
[java] at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:110)
[java] at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1174)
[java] at Test.main(Unknown Source)
BUILD SUCCESSFUL
Total time: 10 seconds


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 11:30 pm 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
Did you have created a hibernate.properties or hibernate.cfg.xml file? If not, create hibernate.properties with the following properties:
Code:
hibernate.connection.driver_class=my.driver.Class
hibernate.connection.url=my://url
hibernate.connection.username=user
hibernate.connection.password=pass
hibernate.dialect=dialect.for.Database

# use it instead Environment.HBM2DDL_AUTO, "create"
hibernate.hbm2ddl.auto=create

Course, put properties' values appropriated for your database. Later, change your code to:
Code:
try {

   Configuration configuration = new Configuration();

   // loading you properties file
   configuration.configure("dir/hibernate.properties")

   SessionFactory sf = configuration.buildSessionFactory();

   Session session = sf.openSession();
   Transaction tx = session.beginTransaction();

   for (int i = 0; i < 200; i++) {
      Customer customer = new Customer();
      customer.setUsername("customer" + i);
      customer.setPassword("customer");
      session.save(customer);
   }

   tx.commit();
}

ps.:Please, use code tags when posting java coding or mappings.

Kind Regards

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 23, 2006 11:32 pm 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
Furthermore, take some time to read this manual section:
Chapter 3. SessionFactory Configuration.

Kind Regards

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 5:03 am 
Newbie

Joined: Wed May 17, 2006 6:31 pm
Posts: 5
hi,
Actually, i have hibernate.cfg.xml, but this time i did as you said, i add hibernate.properties, still error. i really don't know why? Please help me.

Code:
[java] 2006-5-24 10:48:55 org.hibernate.cfg.Environment <clinit>
     [java] information: Hibernate 3.1.3
     [java] 2006-5-24 10:48:55 org.hibernate.cfg.Environment <clinit>
     [java] information: loaded properties from resource hibernate.properties: {hibernate.connection.username=root , hibernate.connection.password=****, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=org.hibernate.dialect.MySQLDialect , hibernate.connection.url=jdbc:mysql://localhost:3306/test , hibernate.connection.driver_class=org.gjt.mm.mysql.Driver, hibernate.hbm2ddl.auto=create}
     [java] 2006-5-24 10:48:55 org.hibernate.cfg.Environment <clinit>
     [java] information: using CGLIB reflection optimizer
     [java] 2006-5-24 10:48:55 org.hibernate.cfg.Environment <clinit>
     [java] information: using JDK 1.4 java.sql.Timestamp handling
     [java] 2006-5-24 10:48:55 org.hibernate.cfg.Configuration configure
     [java] information: configuring from resource: hibernate.properties
     [java] 2006-5-24 10:48:55 org.hibernate.cfg.Configuration getConfigurationInputStream
     [java] information: Configuration resource: hibernate.properties
     [java] 2006-5-24 10:48:55 org.hibernate.util.XMLHelper$ErrorLogger error
     [java] serious: Error parsing XML: hibernate.properties(1) Content is not allowed in prolog.
     [java] org.hibernate.HibernateException: Could not parse configuration: hibernate.properties
     [java] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1376)
     [java] at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
     [java] at Test.main(Unknown Source)
     [java] Caused by: org.dom4j.DocumentException: Error on line 1 of document  : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.
     [java] at org.dom4j.io.SAXReader.read(SAXReader.java:482)
     [java] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1366)


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