Java Mailing List Archive

http://www.gg3721.com/

Home » users.openjpa »

<openjpa-1.1.0-r422266:657916 nonfatal general error> ????

Anish

2008-07-30

Replies: Find Java Web Hosting

Author LoginPost Reply

Hey i have made a little test program using openjpa... this seemed to work
when i did it in windows but somehow doesent work in linux... i am basically
trying to test openjpa with mysql...

the code is as follows:

Main.java
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.  
*/
package hellojpa;

import java.util.*;
import javax.persistence.*;


/**
* A very simple, stand-alone program that stores a new entity in the
* database and then performs a query to retrieve it.
*/
public class Main {

  @SuppressWarnings("unchecked")
  public static void main(String[] args) {
    // Create a new EntityManagerFactory using the System properties.
    // The "hellojpa" name will be used to configure based on the
    // corresponding name in the META-INF/persistence.xml file
    // EntityManagerFactory factory = Persistence.
       EntityManagerFactory emf =
Persistence.createEntityManagerFactory("hellojpa");
    // Create a new EntityManager from the EntityManagerFactory. The
    // EntityManager is the main object in the persistence API, and is
    // used to create, delete, and query objects, as well as access
    // the current transaction
   
   EntityManager em = emf.createEntityManager();
    // Begin a new local transaction so that we can persist a new entity
    em.getTransaction().begin();

    // Create and persist a new Message entity
    em.persist(new Message("Hello Persistence!"));

    // Commit the transaction, which will cause the entity to
    // be stored in the database
    em.getTransaction().commit();

    // It is always good practice to close the EntityManager so that
    // resources are conserved.
    em.close();

    // Create a fresh, new EntityManager
    EntityManager em2 = emf.createEntityManager();

    // Perform a simple query for all the Message entities
    Query q = em2.createQuery("select m from Message m");

    // Go through each of the entities and print out each of their
    // messages, as well as the date on which it was created
    for (Message m : (List<Message>) q.getResultList()) {
       System.out.println(m.getMessage()
          + " (created on: " + m.getCreated() + ")");
    }

    // Again, it is always good to clean up after ourselves
    em2.close();
    emf.close();
  }
}

Message.java
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.  
*/
package hellojpa;

import java.util.*;
import javax.persistence.*;


/**
* A very simple persistent entity that holds a "message", has a
* "created" field that is initialized to the time at which the
* object was created, and an id field that is initialized to the
* current time.
*/
@Entity
public class Message {
  @Id
  private long id = System.currentTimeMillis();

  @Basic
  private String message;

  @Basic
  private Date created = new Date();

  public Message() {
  }

  public Message(String msg) {
    message = msg;
  }

  public void setId(long val) {
    id = val;
  }

  public long getId() {
    return id;
  }

  public void setMessage(String msg) {
    message = msg;
  }

  public String getMessage() {
    return message;
  }

  public void setCreated(Date date) {
    created = date;
  }

  public Date getCreated() {
    return created;
  }
}


persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.  
-->
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  version="1.0">

  <!--
    We need to enumerate each persistent class first in the
persistence.xml
    See: http://issues.apache.org/jira/browse/OPENJPA-78
  -->
  <persistence-unit name="none" transaction-type="RESOURCE_LOCAL">
    <mapping-file>reversemapping/orm.xml</mapping-file>
    <class>hellojpa.Message</class>
    <class>relations.Deity</class>
  </persistence-unit>

  <!--
    A persistence unit is a set of listed persistent entities as well
    the configuration of an EntityManagerFactory. We configure each
    example in a separate persistence-unit.
  -->
  <persistence-unit name="hellojpa" transaction-type="RESOURCE_LOCAL">
    <!--
       The default provider can be OpenJPA, or some other product.
       This element is optional if OpenJPA is the only JPA provider
       in the current classloading environment, but can be specified
       in cases where there are multiple JPA implementations available.
    -->
    <!--
    <provider>
       org.apache.openjpa.persistence.PersistenceProviderImpl
    </provider>
    -->

    <!-- We must enumerate each entity in the persistence unit -->
    <class>hellojpa.Message</class>

    <properties>
       <!--
          We can configure the default OpenJPA properties here. They
          happen to be commented out here since the provided examples
          all specify the values via System properties.
       -->

       
       <property name="openjpa.ConnectionURL"
          value="jdbc:mysql://localhost:3306/jpa"/>
       <property name="openjpa.ConnectionDriverName"
          value="com.mysql.jdbc.Driver"/>
       <property name="openjpa.ConnectionUserName"
          value="root"/>
       <property name="openjpa.ConnectionPassword"
          value="admin"/>
       
    </properties>
  </persistence-unit>

  <!-- persistence unit for the "relations" example -->
  <persistence-unit name="relations" transaction-type="RESOURCE_LOCAL">
    <class>relations.Deity</class>
  </persistence-unit>

  <!-- persistence unit for the "reversemapping" example -->
  <persistence-unit name="reversemapping"
transaction-type="RESOURCE_LOCAL">
    <mapping-file>reversemapping/orm.xml</mapping-file>
  </persistence-unit>
</persistence>


the stack trace...
  [java] Exception in thread "main" <openjpa-1.1.0-r422266:657916
nonfatal general error> org.apache.openjpa.persistence.PersistenceException:
There were errors initializing your configuration:
<openjpa-1.1.0-r422266:657916 fatal store error>
org.apache.openjpa.util.StoreException: com.mysql.jdbc.Driver
  [java]  at
org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource (DataSourceFactory.java:123)
  [java]  at
org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory (JDBCConfigurationImpl.java:776)
  [java]  at
org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory (JDBCConfigurationImpl.java:683)
  [java]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  [java]  at
sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
  [java]  at
sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
  [java]  at java.lang.reflect.Method.invoke (Method.java:597)
  [java]  at
org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll (ConfigurationImpl.java:288)
  [java]  at
org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll (OpenJPAConfigurationImpl.java:1409)
  [java]  at
org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly (AbstractBrokerFactory.java:646)
  [java]  at
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker (AbstractBrokerFactory.java:183)
  [java]  at
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker (DelegatingBrokerFactory.java:142)
  [java]  at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager (EntityManagerFactoryImpl.java:192)
  [java]  at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager (EntityManagerFactoryImpl.java:145)
  [java]  at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager (EntityManagerFactoryImpl.java:56)
  [java]  at hellojpa.Main.main(Main.java:44)
  [java] Caused by: java.lang.ClassNotFoundException:
com.mysql.jdbc.Driver
  [java]  at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
  [java]  at java.security.AccessController.doPrivileged(Native Method)
  [java]  at java.net.URLClassLoader.findClass (URLClassLoader.java:188)
  [java]  at java.lang.ClassLoader.loadClass (ClassLoader.java:306)
  [java]  at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
  [java]  at java.lang.ClassLoader.loadClass (ClassLoader.java:251)
  [java]  at
java.lang.ClassLoader.loadClassInternal (ClassLoader.java:319)
  [java]  at java.lang.Class.forName0(Native Method)
  [java]  at java.lang.Class.forName (Class.java:169)
  [java]  at
org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource (DataSourceFactory.java:85)
  [java]  ... 15 more
  [java]  at
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker (AbstractBrokerFactory.java:196)
  [java]  at
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker (DelegatingBrokerFactory.java:142)
  [java]  at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager (EntityManagerFactoryImpl.java:192)
  [java]  at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager (EntityManagerFactoryImpl.java:145)
  [java]  at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager (EntityManagerFactoryImpl.java:56)
  [java]  at hellojpa.Main.main(Main.java:44)
  [java] Caused by: java.lang.RuntimeException: There were errors
initializing your configuration: <openjpa-1.1.0-r422266:657916 fatal store
error> org.apache.openjpa.util.StoreException: com.mysql.jdbc.Driver
  [java]  at
org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource (DataSourceFactory.java:123)
  [java]  at
org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory (JDBCConfigurationImpl.java:776)
  [java]  at
org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory (JDBCConfigurationImpl.java:683)
  [java]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  [java]  at
sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
  [java]  at
sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
  [java]  at java.lang.reflect.Method.invoke (Method.java:597)
  [java]  at
org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll (ConfigurationImpl.java:288)
  [java]  at
org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll (OpenJPAConfigurationImpl.java:1409)
  [java]  at
org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly (AbstractBrokerFactory.java:646)
  [java]  at
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker (AbstractBrokerFactory.java:183)
  [java]  at
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker (DelegatingBrokerFactory.java:142)
  [java]  at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager (EntityManagerFactoryImpl.java:192)
  [java]  at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager (EntityManagerFactoryImpl.java:145)
  [java]  at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager (EntityManagerFactoryImpl.java:56)
  [java]  at hellojpa.Main.main(Main.java:44)
  [java] Caused by: java.lang.ClassNotFoundException:
com.mysql.jdbc.Driver
  [java]  at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
  [java]  at java.security.AccessController.doPrivileged(Native Method)
  [java]  at java.net.URLClassLoader.findClass (URLClassLoader.java:188)
  [java]  at java.lang.ClassLoader.loadClass (ClassLoader.java:306)
  [java]  at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
  [java]  at java.lang.ClassLoader.loadClass (ClassLoader.java:251)
  [java]  at
java.lang.ClassLoader.loadClassInternal (ClassLoader.java:319)
  [java]  at java.lang.Class.forName0(Native Method)
  [java]  at java.lang.Class.forName (Class.java:169)
  [java]  at
org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource (DataSourceFactory.java:85)
  [java]  ... 15 more
  [java]  at
org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll (ConfigurationImpl.java:302)
  [java]  at
org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll (OpenJPAConfigurationImpl.java:1409)
  [java]  at
org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly (AbstractBrokerFactory.java:646)
  [java]  at
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker (AbstractBrokerFactory.java:183)
  [java]  ... 5 more

Can any one tell me why i am getting this error? or what it means? and how
to fix it...

--
Sent from the OpenJPA Users mailing list archive at Nabble.com.

©2008 gg3721.com - Jax Systems, LLC, U.S.A.