-->
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.  [ 10 posts ] 
Author Message
 Post subject: newbie question
PostPosted: Wed Aug 03, 2005 4:01 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3
Name and version of the database you are using: MySQL 4

Hi guys,

I am trying to get thru the first example of Hibernate tutorial. Two questions.
1. In 9th chapter of Hibernate tutorial it's says that I have to patch up jboss-hibernate.deployer by running ant -f jboss-build.xml fix-hibernate, but where is the jboss-build.xml?

2. I followed first example and create the directory with my POJO, Hibernate utility class and query descriptor, but what should I do with hibernate.cfg.xml? As far as I understand I have to put it in my classpath:
Code:
[root@localhost src]# echo $CLASSPATH
:/home/jboss/server/default/deploy/hibernate.cfg.xml

, which I did, but when I run the example I get errors:


Code:
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 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

BUILD SUCCESSFUL
Total time: 7 seconds


thanks a lot,
webtekie


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 5:20 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 3:15 pm
Posts: 29
Hi, What Hibernate Tutorial has 9 chapters? Do you have link?
Thanks,
B

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 5:21 pm 
Beginner
Beginner

Joined: Wed Jun 08, 2005 10:01 am
Posts: 22
Location: Italy
Hi !

Please post the content of hibernate.cfg.xml

the error....

Quote:
[java] Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not find datasource


...means that Hibernate doesn't know where to connect.

Post the configuration file, please.

Bye
Nic


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 5:56 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
bigbbri: http://www.hibernate.org/hib_docs/v3/re ... index.html (docs off Hibernate main site)

nico.ben
This is my hibernate.cfg.xml :


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:/MySqlDS</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"/>

    </session-factory>

</hibernate-configuration>

But, I think the problem is not with any Hibernate settings (I hope). After this error I tried to connect to MySQl thru a DBDriver I wrote and still no luck. I know the driver works because I used in Fedora 3 and now I use Fedora 4. Everytime I try to run my DBDriver I get error: java.net.SocketException: java.net.SocketException: Invalid argument or cannot assign requested address.
Well, after some googling I found some forums where people say that Fedora 4 and JDK 1.4 do not play well for MySQL connection, but JDK 1.5 works.
So, if there is nothing wrong with my hibernate.cfg.xml and I need to have in my classpath then the problem is in Fedora 4 and JDK1.4 and I have to either switch back to Fedora 3 or upgrade to JDK1.5 which I am not sure I want to do at this time.

thanks for your help,
webtekie


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 6:14 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
Oh, also this is my mysql-ds.xml:

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

<!-- $Id: mysql-ds.xml,v 1.3.2.1 2004/12/01 11:46:00 schrouf Exp $ -->
<!--  Datasource config for MySQL using 3.0.9 available from:
http://www.mysql.com/downloads/api-jdbc-stable.html
-->

<datasources>
  <local-tx-datasource>
    <jndi-name>MySqlDS</jndi-name>
    <connection-url>jdbc:mysql://localhost:3306/mysql</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>root</user-name>
    <password></password>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
    <!-- sql to call when connection is created
    <new-connection-sql>some arbitrary sql</new-connection-sql>
      -->
    <!-- sql to call on an existing pooled connection when it is obtained from pool
    <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
      -->

    <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
    <metadata>
       <type-mapping>mySQL</type-mapping>
    </metadata>
  </local-tx-datasource>
</datasources>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 11:15 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
Ok I figured I'd install JDK1.5 to make Hibernate work, and I did, and it worked...sort of. I am not getting the datasource error, but I am getting this error:

Code:
compile:
    [javac] Compiling 3 source files to /home/jboss-4.0.2/server/default/deploy/hibernate_test.war/bin
    [javac] error: error reading /home/jboss/server/default/deploy/hibernate.cfg.xml; error in opening zip file
    [javac] Note: /home/jboss-4.0.2/server/default/deploy/hibernate_test.war/src/HibernateUtil.java uses unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 1 error



However, hibernate.cfg.xml is in this directory, and what is that error about not being able to open zip file?

thanks,
webtekie


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 9:45 am 
Beginner
Beginner

Joined: Tue Jun 21, 2005 3:15 pm
Posts: 29
have you patched jboss? I do not see any reference in chapter 9 about patching jboss. Are you sure that is the right document?
I saw a posting about jdk1.5 having problems with "error in opening zip file" hope this is not your problem cause then you would really be in a corner.
B

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 10:18 am 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
Ok here it is:

http://docs.jboss.org/jbossas/getting_s ... rnate.html (paragraph 9.1)
Where have you seen posting about jdk1.5 having problems with opening zip file? This looks more and more like Catch 22...

thanks a lot,
webtekie


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 11:30 am 
Beginner
Beginner

Joined: Tue Jun 21, 2005 3:15 pm
Posts: 29
Cannot remember where I saw it. It was through google. sorry. Let's not focus on that. Did you fix the jboss-hibernate.deployer yet? according to the documentation at JBoss there is a jbossj2ee-src.zip file. I do not see the link to it anywhere but it has the jboss-build.xml that you need to run Sun's example on JBoss.
Find it and stay on track with the tutorial and maybe post at JBoss.

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 2:04 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
well the problem is that I can't find jbossj2ee-src.zip anywhere. I searched jboss directory, not there. On the web at http://www.jboss.org/docs/jbossj2ee-src.zip file is not available. Not sure what to do. I think I have to take the long way and go back to Fedora 3.


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