-->
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.  [ 8 posts ] 
Author Message
 Post subject: hibernate.cfg.xml question
PostPosted: Fri Aug 05, 2005 4:51 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
Hi guys,

I am working on the first tutorial on Hibernate. Did everything, and compilation went fine. However, when I try to run ant run -Daction=store I get errors regarding hibernate.cfg.xml file:
Code:
[alex@localhost hibernate_test.war]$ ant run -Daction=store
Buildfile: build.xml

clean:
   [delete] Deleting directory /home/jboss-4.0.2/server/default/deploy/hibernate_test.war/bin
    [mkdir] Created dir: /home/jboss-4.0.2/server/default/deploy/hibernate_test.war/bin

copy-resources:
     [copy] Copying 2 files to /home/jboss-4.0.2/server/default/deploy/hibernate_test.war/bin

compile:
    [javac] Compiling 3 source files to /home/jboss-4.0.2/server/default/deploy/hibernate_test.war/bin

run:
     [java] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
     [java] log4j:WARN Please initialize the log4j system properly.
     [java] Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
     [java] Exception in thread "main" java.lang.ExceptionInInitializerError
     [java]     at HibernateUtil.<clinit>(Unknown Source)
     [java]     at SKUManager.createAndStoreEvent(Unknown Source)
     [java]     at SKUManager.main(Unknown Source)
     [java] Caused by: org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
     [java]     at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1216)
     [java]     at org.hibernate.cfg.Configuration.configure(Configuration.java:1150)
     [java]     at org.hibernate.cfg.Configuration.configure(Configuration.java:1136)
     [java]     ... 3 more
     [java] Caused by: org.dom4j.DocumentException: Error on line 1 of document  : Document root element is missing. Nested exception: Document root element is missing.
     [java]     at org.dom4j.io.SAXReader.read(SAXReader.java:482)
     [java]     at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1206)
     [java]     ... 5 more
     [java] Java Result: 1

BUILD SUCCESSFUL
Total time: 7 seconds


As I understand from the tutorial once I put hibernate.cfg.xml into src directory ant will pick it up and put into bin directory and in turn wrapper will try to read the file by default:

Code:
sessionFactory = new Configuration().configure().buildSessionFactory();


So does the error mean that file could not be read or there is something wrong in the file?

thanks a lot,
webtekie


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 4:57 pm 
Beginner
Beginner

Joined: Tue Jul 12, 2005 10:27 am
Posts: 23
Post your configuration file. It appears it not well formatted.

_________________
- Richard Burton


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 5:26 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
thanks Richard,
yes it was poor formatting of the file. But, now I get error regarding datasource:
Code:
[java] Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not find datasource
     [java] Exception in thread "main" java.lang.ExceptionInInitializerError
     [java]     at HibernateUtil.<clinit>(Unknown Source)
     [java]     at SKUManager.createAndStoreEvent(Unknown Source)
     [java]     at SKUManager.main(Unknown Source)
     [java] Caused by: org.hibernate.HibernateException: Could not find datasource
     [java]     at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:56)
     [java]     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
     [java]     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
     [java]     at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:362)
     [java]     at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)
     [java]     at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1502)
     [java]     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1031)
     [java]     ... 3 more
     [java] Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resour
ce file:  java.naming.factory.initial
     [java]     at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:640)
     [java]     at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
     [java]     at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
     [java]     at javax.naming.InitialContext.lookup(InitialContext.java:347)
     [java]     at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
     [java]     ... 9 more
     [java] Java Result: 1


and here is my cfg.xml file:

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <!-- a SessionFactory instance listed as /jndi/name -->
    <session-factory
        name="java:hibernate/SessionFactory">

        <!-- properties -->
        <property name="connection.datasource">java:/mydb</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="show_sql">false</property>
        <property name="transaction.factory_class">
            org.hibernate.transaction.JTATransactionFactory
        </property>
        <property name="jta.UserTransaction">java:comp/UserTransaction</property>

        <!-- mapping files -->
        <mapping resource="SKU.hbm.xml"/>

        <!-- cache settings -->

    </session-factory>

</hibernate-configuration>


I know connection to database works because I tested it straight to JDBC from my own class, so what could be the issue?

thanks again,
webtekie


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 5:32 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
This error has to do with your environment.

Specifically
Code:
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resour
ce file:  java.naming.factory.initial


Are you running this inside an AppServer ?

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 5:34 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
yes, jboss 4.0.2.
What env should I set?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 5:39 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
webtekie wrote:
yes, jboss 4.0.2.
What env should I set?


They should be set in -...\jboss-4.0.2\server\default\conf\jndi.properties should have it defined. Not sure why it would've changed.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 5:41 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
thanks, but the file says:

Code:
# DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING
#
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces


And I don't know what I am doing with this file so help is greatly appreciated.

thanks again,
webtekie


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 5:54 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
Also,

In reference it says:
Code:
Note that this class [HibernateUtil] is not necessary if you deploy Hibernate in a J2EE application server: a Session will be automatically bound to the current JTA transaction and you can look up the SessionFactory through JNDI. If you use JBoss AS, Hibernate can be deployed as a managed system service and will automatically bind the SessionFactory to a JNDI name.


So how do I deploy Hibernate as a managed system service?


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