-->
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.  [ 9 posts ] 
Author Message
 Post subject: Can someone show me where am I going wrong?! - Thanks
PostPosted: Wed Aug 08, 2007 5:56 am 
Newbie

Joined: Tue Dec 20, 2005 5:47 pm
Posts: 13
Here is all the info:

Hibernate version:3.2

Mapping documents:
Code:
<hibernate-mapping
   package="com.integrallis.techconf.domain">
   <class name="Address">
      <id name="Id" column="PK_ID" type="integer">
         <generator class="identity"/>
      </id>
      <property name="StreetAddress"/>
      <property name="State"/>
      <property name="ZipCode"/>
      <property name="City"/>
      <property name="AptNumber"/>
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
Address address = new Address();
      
      Configuration config = new Configuration().
          setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialact").
         setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver").
         setProperty("hibernate.connection.url", "jdbc:mysql://localhost/tcms").
         setProperty("hibernate.connection.username", "root").
         setProperty("hibernate.connection.password", "eskimo").
         setProperty("hibernate.show_sql", "true");
         
      config.addClass(Address.class);
      
      SessionFactory factory = config.buildSessionFactory();
      
      Session session = null;
      Transaction tx = null;
      
      try {
         session = factory.openSession();
         tx = session.beginTransaction();
         session.persist(address);
         tx.commit();
      }catch(Exception ex) {
         if(tx != null) tx.rollback();
      }finally {
         session.close();
      }


Full stack trace of any exception that occurs:
Code:
Error parsing XML: XML inputstream(1) Document root element "hibernate-mapping", mush match DOCTYPE root
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping documents from resource
at org.hibernate.cfg.Configuration.addResource(Configuration.java:539)
at org.hibernate.cfg.Configuration.addClass(Configuration.java:586)
at com.integrallis.techconf.domain.Address.main(Address.java:98)
...


Name and version of the database you are using:
MySQL 5.1 and Database "tcms"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 6:03 am 
Newbie

Joined: Mon Jun 11, 2007 5:45 am
Posts: 8
Add this line to the top of your mapping file?

Code:
<?xml version="1.0" encoding="utf-8" ?>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 6:54 am 
Newbie

Joined: Tue Jul 31, 2007 10:32 am
Posts: 17
Location: Amsterdam
Check the syntax according to the hibernate DTD definition, to be found in :

http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd

I am not sure which IDE you are using, but if you are using Eclipse, it will help to use the following in the header to make sure Eclipse helps you find the problems instantly:

Code:
<?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
                  package="com.integrallis.techconf.domain">
   <class name="Address">
      <id name="Id" column="PK_ID" type="integer">
         <generator class="identity"/>
      </id>
      <property name="StreetAddress"/>
      <property name="State"/>
      <property name="ZipCode"/>
      <property name="City"/>
      <property name="AptNumber"/>
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 7:02 am 
Newbie

Joined: Tue Dec 20, 2005 5:47 pm
Posts: 13
Thanks bertvan,

I have tried that and it is still giving me same error message.


Code:
Error parsing XML: XML inputstream(1) Document root element "hibernate-mapping", mush match DOCTYPE root "null"
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping documents from resource com/integrallis/techconf/domain/Address.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:539)
at org.hibernate.cfg.Configuration.addClass(Configuration.java:586)
at com.integrallis.techconf.domain.Address.main(Address.java:98)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 7:29 am 
Newbie

Joined: Tue Dec 20, 2005 5:47 pm
Posts: 13
Thanks mkarami,

Your suggestion has worked and I have another new error.

Code:
INFO: Not binding factory to JNDI, no JNDI name configured
Exception in thread "main" java.lang.NullPointerException
at com.integrallis.techconf.domain.Address.main(Address.java:116)


At Address.java line 116 is "session.close()"

Can you help me with this error?

Cheers!

PS: I am using a notepad and ant to build my project.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 7:46 am 
Newbie

Joined: Tue Jul 31, 2007 10:32 am
Posts: 17
Location: Amsterdam
Ok. Good to see it helped. plz do not forget to rate the replies if it has helped you solve your problem.

Concerning the JNDI, sounds strange. Looking to your code i find it peculiar that you close your session using the session object. Normally the sessionfactory should take care of this. Try the following:

Code:
1- session = factory.getCurrentSession();

2- session.beginTransaction();

3- ...do what ever you want with your domain objects.....

4- session.save();

5- session.getTransaction().commit;

6- factory.close()


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 8:36 am 
Newbie

Joined: Tue Dec 20, 2005 5:47 pm
Posts: 13
Thanks again!

I have changed session.close() to factory.close() from your example and I get another error message.

Code:
INFO:  cleaning up connections pool: jdbc//localhost/tcms
Exception in thread "main" java.lang.NoClassDefFoundError: javax/transaction/Synchronization
at org.hibernate.impl.SessionImpl.<init>(SessionImpl.java:213)
at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java: 473)
at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java: 497)
...


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 3:39 am 
Newbie

Joined: Tue Jul 31, 2007 10:32 am
Posts: 17
Location: Amsterdam
my first reaction is that your classpath is not correct. Arte you using an IDE to build your application? Since using and IDE such as Eclipse would make it easier to set your classpath right.
Check your classpath settings.

Cheers, M


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 5:39 pm 
Newbie

Joined: Tue Dec 20, 2005 5:47 pm
Posts: 13
mkarami,

You are right once again. I have not had defined my classpath as it should have been. Finally I have decided to use Eclipse IDE and on this occasion it has worked. I have been working all day to work out why my ant build has not worked and guess what I have not defined all the classpath.

No surprises there!

Thanks


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