-->
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: Tutorial Help...
PostPosted: Tue May 18, 2010 5:37 pm 
Newbie

Joined: Tue May 18, 2010 5:28 pm
Posts: 8
I'm currently working on a hibernate/Java/hyper sql Database application, and I am in need of assistance.

Here is the tutorial I'm working through.
http://today.java.net/pub/a/today/2006/05/23/ejb3-persistence-api-for-client-side-developer.html

I have all the required jars, but I get the following results and then an exception. I'm running it in NetBeans:
Code:
run:
May 18, 2010 4:24:22 PM org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.3.1.GA
May 18, 2010 4:24:22 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
May 18, 2010 4:24:22 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
May 18, 2010 4:24:22 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
May 18, 2010 4:24:22 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
May 18, 2010 4:24:22 PM org.hibernate.ejb.Version <clinit>
INFO: Hibernate EntityManager 3.3.2.GA
May 18, 2010 4:24:23 PM org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: addressbook.Person
May 18, 2010 4:24:23 PM org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity addressbook.Person on table Person
May 18, 2010 4:24:23 PM org.hibernate.cfg.AnnotationConfiguration secondPassCompile
INFO: Hibernate Validator not found: ignoring
May 18, 2010 4:24:23 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
May 18, 2010 4:24:23 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
May 18, 2010 4:24:23 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: true
May 18, 2010 4:24:23 PM org.hibernate.connection.DriverManagerConnectionProvider configure
SEVERE: JDBC Driver class not found:
java.lang.ClassNotFoundException:
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
        at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
        at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
        at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
        at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
        at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
        at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
        at addressbook.Main.init(Main.java:17)
        at addressbook.Main.main(Main.java:52)
Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: sample] Unable to build EntityManagerFactory
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
        at addressbook.Main.init(Main.java:17)
        at addressbook.Main.main(Main.java:52)
Caused by: org.hibernate.HibernateException: JDBC Driver class not found:
        at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:66)
        at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
        at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
        at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
        at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
        at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
        ... 5 more
Caused by: java.lang.ClassNotFoundException:
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
        at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
        ... 12 more
Java Result: 1



Any help would be appreciated. = /


Top
 Profile  
 
 Post subject: Re: Tutorial Help...
PostPosted: Tue May 18, 2010 6:01 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
you have to add the JDBC driver you want to use on the classpath.
(in the case of the article you pointed out it means you're missing hsqldb.jar)

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Tutorial Help...
PostPosted: Wed May 19, 2010 9:49 am 
Newbie

Joined: Tue May 18, 2010 5:28 pm
Posts: 8
Yes, I have that jar in my class path. That's why I'm confused. = /


Top
 Profile  
 
 Post subject: Re: Tutorial Help...
PostPosted: Wed May 19, 2010 1:14 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Using an old java version? JDBC4 drivers require java6

Or check The driver classname you're referring to didn't change

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Tutorial Help...
PostPosted: Wed May 19, 2010 6:47 pm 
Newbie

Joined: Tue May 18, 2010 5:28 pm
Posts: 8
I'm running Java 6, and I'm not sure if the class names would have changed. How would I check that? = /. Here's my persistence.xml file, if that helps.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="sample" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>addressbook.Person</class>
    <properties>
      <property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="hibernate.connection.username" value="app"/>
      <property name="hibernate.connection.password" value=""/>
      <property name="hibernate.connection.url" value="jdbc:derby://localhost:1527/sample"/>
      <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
      <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
  </persistence-unit>
</persistence>


I'm using the latest version of hibernate, and the latest version of hsqldb. Thanks for the responses so far! =)


Top
 Profile  
 
 Post subject: Re: Tutorial Help...
PostPosted: Thu May 20, 2010 1:47 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Derby is not HSQL: you're using a wrong connection.driver_class, just remove The property it will pick the right one.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Tutorial Help...
PostPosted: Thu May 20, 2010 3:15 pm 
Newbie

Joined: Tue May 18, 2010 5:28 pm
Posts: 8
Thanks a bunch, I should have noticed that. It is working now. Thanks soooooo much for your help. =)


Top
 Profile  
 
 Post subject: Re: Tutorial Help...
PostPosted: Thu May 20, 2010 7:01 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
cool :) you're welcome

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Tutorial Help...
PostPosted: Fri May 21, 2010 3:01 pm 
Newbie

Joined: Tue May 18, 2010 5:28 pm
Posts: 8
Ok, LAST QUESTION lol. I have only one more issue. I'm trying to start HSQLDB from within my program so the user doesn't have to start it and stop it manually each time.
Here is my startStop class

Code:
package addressbook;
import java.sql.*;

public class StartStopHSQLDB {

        private Connection c = null;

        public void startHSQLDB(){
            //Start Hypersonic
            try{
            Class.forName("org.hsqldb.jdbcDriver").newInstance();

            c = DriverManager.getConnection(
                    "jdbc:hsqldb:file:test", "sa", "");

            }catch(ClassNotFoundException e){
                e.printStackTrace();
            }catch(SQLException e){
                e.printStackTrace();
            }catch(Exception e){
                e.printStackTrace();
            }

        }

        public void stopHSQLDB(){
            //Shutdown Hypersonic
            try{
            Statement stmt = c.createStatement();
            stmt.execute("SHUTDOWN");
            c.close();
            }catch(SQLException e){
                e.printStackTrace();
            }
        }
}


I start the database by creating an object and calling the startHSQLDB() method and that's the first thing my main method does. And here's the exception that I get

Code:
May 21, 2010 1:59:04 PM org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.3.1.GA
May 21, 2010 1:59:04 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
May 21, 2010 1:59:04 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
May 21, 2010 1:59:04 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
May 21, 2010 1:59:04 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
May 21, 2010 1:59:04 PM org.hibernate.ejb.Version <clinit>
INFO: Hibernate EntityManager 3.3.2.GA
May 21, 2010 1:59:04 PM org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: addressbook.Person
May 21, 2010 1:59:04 PM org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity addressbook.Person on table Person
May 21, 2010 1:59:04 PM org.hibernate.cfg.AnnotationConfiguration secondPassCompile
INFO: Hibernate Validator not found: ignoring
May 21, 2010 1:59:04 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
May 21, 2010 1:59:04 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
May 21, 2010 1:59:04 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: true
May 21, 2010 1:59:04 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hsql://localhost
May 21, 2010 1:59:04 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=sa, password=****, autocommit=true, release_mode=auto}
May 21, 2010 1:59:05 PM org.hibernate.cfg.SettingsFactory buildSettings
WARNING: Could not obtain connection metadata
java.sql.SQLException: socket creation error
        at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
        at org.hsqldb.jdbc.jdbcConnection.<init>(Unknown Source)
        at org.hsqldb.jdbcDriver.getConnection(Unknown Source)
        at org.hsqldb.jdbcDriver.connect(Unknown Source)
        at java.sql.DriverManager.getConnection(DriverManager.java:582)
        at java.sql.DriverManager.getConnection(DriverManager.java:154)
        at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
        at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84)
        at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
        at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
        at addressbook.Main.init(Main.java:18)
        at addressbook.Main.main(Main.java:69)
Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: sample] Unable to build EntityManagerFactory
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
        at addressbook.Main.init(Main.java:18)
        at addressbook.Main.main(Main.java:69)
Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
        at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
        at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
        at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:426)
        at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:128)
        at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
        at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
        ... 5 more
Java Result: 1


And here's my persistence.xml file if that helps with anything...

Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="sample" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>addressbook.Person</class>
    <properties>
      <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
      <property name="hibernate.connection.username" value="sa"/>
      <property name="hibernate.connection.password" value=""/>
      <property name="hibernate.connection.url" value="jdbc:hsqldb:hsql://localhost"/>
      <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
  </persistence-unit>
</persistence>


Do I need to move my database driver to a different location or would I need to move my database?


Top
 Profile  
 
 Post subject: Re: Tutorial Help...
PostPosted: Fri May 21, 2010 3:05 pm 
Newbie

Joined: Tue May 18, 2010 5:28 pm
Posts: 8
Nevermind, figured it out. Sorry!


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.