-->
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: Entity Manager
PostPosted: Mon Aug 15, 2005 10:28 am 
Beginner
Beginner

Joined: Mon Mar 07, 2005 12:02 pm
Posts: 39
Im trying to figure out this entity manager thing. So please bare with me. Why am I getting this error, the JDBC driver I use is in the classpath of my eclipse.
Code:
SEVERE: JDBC Driver class not found:
java.lang.ClassNotFoundException:
   at java.lang.Class.forName0(Native Method)
   at java.lang.Class.forName(Unknown Source)
   at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:109)
   at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
   at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
   at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
   at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:362)
   at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)
   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1502)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1031)
   at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:472)
   at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:385)
   at org.hibernate.ejb.HibernatePersistence.createFactory(HibernatePersistence.java:152)
   at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:199)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27)
   at co.za.easypay.reportconfig.GetTest.main(GetTest.java:13)
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.HibernateException: JDBC Driver class not found:
   at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:206)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
   at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27)
   at co.za.easypay.reportconfig.GetTest.main(GetTest.java:13)
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.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
   at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:362)
   at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)
   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1502)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1031)
   at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:472)
   at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:385)
   at org.hibernate.ejb.HibernatePersistence.createFactory(HibernatePersistence.java:152)
   at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:199)
   ... 3 more
Caused by: java.lang.ClassNotFoundException:
   at java.lang.Class.forName0(Native Method)
   at java.lang.Class.forName(Unknown Source)
   at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:109)
   at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
   ... 13 more


persistence.xml

Code:

<entity-manager>
   <name>manager1</name>
   <class>co.za.easypay.reportconfig.Person</class>
   <properties>
      <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
      <property name="hibernate.show_sql">true</property>
      <property name="hibernate.use_outer_join">false</property>
      <property name="hibernate.connection.username">root</property>
      <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="hibernate.connection.url">jdbc:mysql://196.34.50.153:3306/bps_hibernate</property>
       <!-- alternatively to <class> and <property> declarations, you can use a regular hibernate.cfg.xml file -->
       <!-- property name="hibernate.ejb.cfgfile" value="/org/hibernate/ejb/test/hibernate.cfg.xml"/ -->
   </properties>
</entity-manager>


running code

Code:

package co.za.easypay.reportconfig;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import com.mysql.jdbc.Driver;



public class GetTest {
public static void main(String[]args){

   EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager1");
   EntityManager em = emf.createEntityManager(); // Retrieve a transactional-scoped entity manager
   em.close();

   emf.close();
}
}


annotated class

Code:
package co.za.easypay.reportconfig;

import java.io.Serializable;

import javax.persistence.Id;
import javax.persistence.*;


@Entity
@Table(name="person_tbl")
public class Person implements Serializable {
    private Long id;
    public String email_address;

    @Id
    public Long getId() { return id; }

    public void setId(Long id) { this.id = id; }

   public String getEmail_address() {
      return email_address;
   }

   public void setEmail_address(String email_address) {
      this.email_address = email_address;
   }

}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 15, 2005 10:47 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
I'm not an Eclipse user, but it definitely looks like you don't have Driver class in your classpath. Since Hibernate tries to find your driver class through various class loaders and it definitely didn't find yours.
Check out libarary settings and ofcourse classpath. It is probably a simple mistake.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 15, 2005 11:05 am 
Beginner
Beginner

Joined: Mon Mar 07, 2005 12:02 pm
Posts: 39
nawh, I even when't crazy and added the jar to my jre/lib/ext folder and it still didn't see it. What bothers me is that it didn't specify which class it could not found. Maybe there is something wrong with my persistence.xml file


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 15, 2005 11:16 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
JDBC Driver class not found: <missing class name>

There should be a value.

Try changing your Hibernate properites in persistence.xml to this:

<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>

instead of:

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>

Different value spec.

Maybe it will work. :-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 15, 2005 4:25 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I guess it makes sense to support both notations. Add a JIRA issue please.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 3:47 am 
Beginner
Beginner

Joined: Mon Mar 07, 2005 12:02 pm
Posts: 39
It already supports both notations. I changed it to that way but stillnot fixed. Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 3:58 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Debug.

And write what is the driverClassName.

Since it looks really weird that there is no code after ClassNotFoundException - that it doesn't say which class is missing.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 4:33 am 
Beginner
Beginner

Joined: Mon Mar 07, 2005 12:02 pm
Posts: 39
Ok, there is definitly something wrong. I debugged the thing and at PersistanceMetadata.getProps() line 93 the value of prop is {hibernate.connection.username=, hibernate.dialect=, hibernate.use_outer_join=, hibernate.show_sql=, hibernate.connection.driver_class=}
It doesn't add the actual values of the poperties I specified. Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 6:09 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The debug result appears clearly when you use
<property name="blah">blah</property>

So use
<property name="blah" value="blah"/>

_________________
Emmanuel


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.