openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lars Vogel" <lars.vo...@googlemail.com>
Subject Re: JPA - Null pointer exception
Date Wed, 12 Mar 2008 21:28:00 GMT
Hi Mike,

thank you, I must have been blind. Indeed the OpenJPA was missing.

Thank you very, very much and sorry for such a blind spot on my side.

I'll write a short summery on how to set a small OpenJPA up and post it
later to this newsgroup for future reference.

Best regards, Lars


2008/3/12, Michael Dick <michael.d.dick@gmail.com>:
>
> The only thing I noticed was that you didn't have OpenJPA specified on the
> classpath. You must have it specified somewhere, unless you've imported all
> the source.
>
> I'm sorry to say that I just replied to you personally, so the users
> mailing list hasn't seen these last few replies. If you'd like to post the
> sample you're using back to users@openjpa.apache.org, then maybe someone
> else will have better luck than I did.
>
> -Mike
>
> On Wed, Mar 12, 2008 at 3:53 PM, Lars Vogel <lars.vogel@googlemail.com>
> wrote:
>
> > Hi Mike,
> >
> > thank you. I don't see a difference to "my" setup.
> >
> > If anyone wants to look at my project I uploaded it:
> > http://www.jnerlich.de/JPAExample.zip
> >
> > Cheers, Lars
> >
> >
> > 2008/3/12, Michael Dick <michael.d.dick@gmail.com>:
> > >
> > > Hi Lars,
> > >
> > > Here's what I'm using. I don't see anything obviously wrong the ones
> > > you sent me though.
> > >
> > > -Mike
> > >
> > > On Wed, Mar 12, 2008 at 2:52 PM, Lars Vogel <lars.vogel@googlemail.com>
> > > wrote:
> > >
> > > > Hi Mike,
> > > >
> > > > I'm running it in Eclipse. Yes, please send me your .classpath and
> > > > .project files. Mine are also attached for reference.
> > > >
> > > > Best regards, Lars
> > > >
> > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > <projectDescription>
> > > >     <name>hellopja</name>
> > > >     <comment></comment>
> > > >     <projects>
> > > >     </projects>
> > > >     <buildSpec>
> > > >         <buildCommand>
> > > >             <name>org.eclipse.jdt.core.javabuilder</name>
> > > >             <arguments>
> > > >             </arguments>
> > > >         </buildCommand>
> > > >     </buildSpec>
> > > >     <natures>
> > > >         <nature>org.eclipse.jdt.core.javanature</nature>
> > > >     </natures>
> > > > </projectDescription>
> > > >
> > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > <classpath>
> > > >     <classpathentry kind="src" path="src"/>
> > > >     <classpathentry kind="con" path="
> > > > org.eclipse.jdt.launching.JRE_CONTAINER"/>
> > > >     <classpathentry kind="lib" path="C:/Documents and
> > > > Settings/vogella/Desktop/Documents/08_MyDocuments/15_EclipseLibs/openjpa/commons-
> > > > collections-3.2.jar"/>
> > > >     <classpathentry kind="lib" path="C:/Documents and
> > > > Settings/vogella/Desktop/Documents/08_MyDocuments/15_EclipseLibs/openjpa/commons-
> > > > lang-2.1.jar"/>
> > > >     <classpathentry kind="lib" path="C:/Documents and
> > > > Settings/vogella/Desktop/Documents/08_MyDocuments/15_EclipseLibs/openjpa/commons-
> > > > logging-1.0.4.jar"/>
> > > >     <classpathentry kind="lib" path="C:/Documents and
> > > > Settings/vogella/Desktop/Documents/08_MyDocuments/15_EclipseLibs/openjpa/commons-
> > > > pool-1.3.jar"/>
> > > >     <classpathentry kind="lib" path="C:/Documents and
> > > > Settings/vogella/Desktop/Documents/08_MyDocuments/15_EclipseLibs/openjpa/derby-
> > > > 10.2.2.0.jar"/>
> > > >     <classpathentry kind="lib" path="C:/Documents and
> > > > Settings/vogella/Desktop/Documents/08_MyDocuments/15_EclipseLibs/openjpa/geronimo-jms_1.1_spec-
> > > > 1.0.1.jar"/>
> > > >     <classpathentry kind="lib" path="C:/Documents and
> > > > Settings/vogella/Desktop/Documents/08_MyDocuments/15_EclipseLibs/openjpa/geronimo-jpa_3.0_spec-
> > > > 1.0.jar"/>
> > > >     <classpathentry kind="lib" path="C:/Documents and
> > > > Settings/vogella/Desktop/Documents/08_MyDocuments/15_EclipseLibs/openjpa/geronimo-jta_1.1_spec-
> > > > 1.1.jar"/>
> > > >     <classpathentry kind="lib" path="C:/Documents and
> > > > Settings/vogella/Desktop/Documents/08_MyDocuments/15_EclipseLibs/openjpa/serp-
> > > > 1.13.1.jar"/>
> > > >     <classpathentry kind="output" path="bin"/>
> > > > </classpath>
> > > >
> > > >
> > > > 2008/3/12, Michael Dick <michael.d.dick@gmail.com>:
> > > >
> > > > > Hi Lars,
> > > > >
> > > > > How are you running the program? You mention projects so you're
> > > > > probably using either Eclipse or Netbeans. I tried something similar
to what
> > > > > you've posted and it worked for me in Eclipse. I can send you the
.classpath
> > > > > and .project files if that will help.
> > > > >
> > > > > -Mike
> > > > >
> > > > > On Wed, Mar 12, 2008 at 10:22 AM, Lars Vogel <
> > > > > lars.vogel@googlemail.com> wrote:
> > > > >
> > > > > > Hi Venkatesch,
> > > > > >
> > > > > > I did also modify the orginal persistence.xml so that is exactly
> > > > > > the same as
> > > > > > my example to be able to run Main.java directly without the
ant
> > > > > > script.
> > > > > >
> > > > > > So in both cases I'm not using the build.xml file anymore. The
> > > > > > only
> > > > > > difference I see is that one version runs the other not.
> > > > > >
> > > > > > Best egards, Lars
> > > > > >
> > > > > > 2008/3/12, Addanki, Venkatesh <Venkatesh.Addanki@aquilent.com>:
> > > > > > >
> > > > > > > Lars,
> > > > > > >
> > > > > > > One obvious difference between your code and the out of
box
> > > > > > sample is
> > > > > > > the way the driver class and its properties are specified.
> > > > > > build.xml vs
> > > > > > > persistence.xml.  It looks like the
> > > > > > org.apache.derby.jdbc.EmbeddedDriver
> > > > > > > class from your persistence.xml is not being found or the
> > > > > > connection url
> > > > > > > is not getting through.
> > > > > > >
> > > > > > > Regards
> > > > > > >
> > > > > > > V
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: Lars Vogel [mailto:lars.vogel@googlemail.com]
> > > > > > > Sent: Wednesday, March 12, 2008 9:22 AM
> > > > > > > To: users@openjpa.apache.org
> > > > > > > Subject: JPA - Null pointer exception
> > > > > > >
> > > > > > > Hi,
> > > > > > >
> > > > > > > I trying to make JPA work for me. The delivered example
works
> > > > > > without
> > > > > > > problems, I can also successfully modify this example.
The
> > > > > > example was
> > > > > > > based on http://openjpa.apache.org/quick-start.html.
> > > > > > >
> > > > > > > But if I create a new project the Entity Manager returns
only
> > > > > > a NULL
> > > > > > > value.
> > > > > > > Error:
> > > > > > >
> > > > > > > Exception in thread "main" java.lang.NullPointerException
> > > > > > >     at hellojpa.Main.main(Main.java:44)
> > > > > > >
> > > > > > >
> > > > > > > I use the same files as in the working example. All jars
are
> > > > > > included in
> > > > > > > the build path. I assume that the persistence.xml is not
found
> > > > > > but to my
> > > > > > > knowledge the classpath is correctly maintained. The path
> > > > > > .../bin
> > > > > > > contains the directory META-INF and here the file
> > > > > > persistence.xml.
> > > > > > >
> > > > > > > Any advice? I must be missing something very simple but
cannot
> > > > > > figure it
> > > > > > > out. For example coding please see below.
> > > > > > >
> > > > > > > Best regards, Lars
> > > > > > >
> > > > > > > File structure:
> > > > > > >
> > > > > > > src
> > > > > > >   - hellojpa
> > > > > > >      - Main.java
> > > > > > >      - Message.java
> > > > > > > - META-INF
> > > > > > >       - persistence.xml
> > > > > > >
> > > > > > > Same structure in the bin directory.
> > > > > > >
> > > > > > >
> > > > > > > -----------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">
> > > > > > >
> > > > > > >     <!--
> > > > > > >         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>
> > > > > > >             <property name="openjpa.ConnectionURL"
> > > > > > >
> > > > > > >
> > > > > > value="jdbc:derby:C:/DerbyDatabases/hellojpa-database5;create=true"
/>
> > > > > > >             <property name="openjpa.ConnectionDriverName"
> > > > > > >                 value="org.apache.derby.jdbc.EmbeddedDriver"
> > > > > > />
> > > > > > >             <property name="openjpa.ConnectionUserName"
> > > > > > value="" />
> > > > > > >             <property name="openjpa.ConnectionPassword"
> > > > > > value="" />
> > > > > > >
> > > > > > >             <!--
> > > > > > >                 Tell OpenJPA to automatically create tables
in
> > > > > > the
> > > > > > > database
> > > > > > >                 for entities. Note that this should be
> > > > > > disabled when
> > > > > > >                 running against a production database,
since
> > > > > > you
> > > > > > > probably
> > > > > > >                 don't want to be altering the schema at
> > > > > > runtime.
> > > > > > >             -->
> > > > > > >             <property name="openjpa.jdbc.SynchronizeMappings"
> > > > > > >                 value="buildSchema" />
> > > > > > >
> > > > > > >         </properties>
> > > > > > >     </persistence-unit>
> > > > > > >
> > > > > > > </persistence>
> > > > > > >
> > > > > > >
> > > > > > > -----------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) {
> > > > > > >         System.out.println(System.getProperty("java.class.path
> > > > > > "));
> > > > > > >         // 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.
> > > > > > >             createEntityManagerFactory("hellojpa",
> > > > > > > System.getProperties());
> > > > > > >
> > > > > > >         // 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 = factory.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 = factory.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();
> > > > > > >         factory.close();
> > > > > > >     }
> > > > > > > }
> > > > > > >
> > > > > > > -----------
> > > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > >
> > >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message