Hi David,
Thanks for the additional information.  A couple of things to comment on...

For some reason, you are getting different exception text than the first one
you posted.  This exception text actually points back to your Person entity,
so that's good:

<openjpa-1.2.0-r422266:683325 fatal user error>
org.apache.openjpa.persistence.ArgumentException: No table was given for
persistent type "net.leangen.expedition.openjpa.internal.Person".

Since we seem to be tripping over the tables, is there any chance that this
problem is related to the other problem you've posted about the Schema Tool
not generating the tables as expected?  From your configuration and the call
stack, it looks like you are using the SynchronizeMappings property to help
create the tables.

I see that you have the <enhancer> element specific in your pom.xml.  Have
you ensured that your entities are getting enhanced, either statically at
build time or dynamically via a javaagent?  The property
openjpa.RuntimeUnenhancedClasses set to "warn" or "unsupported" would help
isolate this situation.

It looks like our metadata repository is not getting populated correctly for
this Person entity before we attempt to create the tables.  I'm not seeing
anything in what you have provided that jumps out at me as being a problem.

It sounds like you've tried stepping through the code.  What about TRACE?
Sometimes, the Trace output indicates an earlier condition that is now
affecting the current condition.

If none of this helps isolate the problem, then we might have to actually
try to reproduce it...  :-)  Like I said, I don't see anything unique with
your setup.  Pretty vanilla.

Kevin


On Thu, Mar 26, 2009 at 8:24 PM, David Leangen <k...@leangen.net> wrote:

>
> Thank you, Kevin.
>
>
> On Thu, 2009-03-26 at 09:01 -0500, Kevin Sutter wrote:
> > Hi David,
> > I think we'll need a bit more information.
>
> Ok, no problem.
>
> I kept fiddling, but still no luck. I noticed that when stepping through
> the code, even with the @Table annotation, for some reason value for
> "given" is null.
>
> Anyway, here goes:
>
> Entity
> _______________________________________________
> package net.leangen.expedition.openjpa.internal;
>
> import javax.persistence.*;
>
> @Entity
> @Table( name="person" )
> public final class Person
> {
>    private static final long serialVersionUID = 1L;
>
>    private String sin;
>    private String name;
>
>    public Person(){}
>
>    public Person( String aSin, String aName )
>    {
>        sin = aSin;
>        name = aName;
>    }
>
>    @Id
>    public String getSin()
>    {
>        return sin;
>    }
>
>    public void setSin( String sin )
>    {
>        this.sin = sin;
>    }
>
>    @Basic
>    public String getName()
>    {
>        return name;
>    }
>
>    public void setName( String name )
>    {
>        this.name = name;
>    }
>
>    @Override
>    public String toString()
>    {
>        return getName();
>    }
>
>    @Override
>    public boolean equals( Object o )
>    {
>        if( this == o )
>            return true;
>
>        if( !( o instanceof Person ) )
>            return false;
>
>        final Person that = (Person)o;
>        return this.getSin().equals( that.getSin() );
>    }
>
>    @Override
>    public int hashCode()
>    {
>        return 17*getSin().hashCode();
>    }
> }
>
> persistence.xml (edited)
> _______________________________________________
> <?xml version="1.0"?>
> <persistence xmlns="http://java.sun.com/xml/ns/persistence";
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>    version="1.0">
>  <persistence-unit name="openjpa">
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>    <class>net.leangen.expedition.openjpa.internal.Person</class>
>    <properties>
>      <property name="openjpa.ConnectionURL"
> value="jdbc:postgresql://xxxxx/xxxxx"/>
>      <property name="openjpa.ConnectionDriverName"
> value="org.postgresql.Driver"/>
>      <property name="openjpa.ConnectionUserName" value="xxxxx"/>
>      <property name="openjpa.ConnectionPassword" value="xxxxx"/>
>      <property name="openjpa.Log" value="DefaultLevel=WARN,
> Tool=INFO"/>
>      <property name="openjpa.jdbc.SynchronizeMappings"
> value="buildSchema(ForeignKeys=true)"/>
>    </properties>
>  </persistence-unit>
> </persistence>
>
> "main" code
> _______________________________________________
>        final EntityManagerFactory entityManagerFactory =
> Persistence.createEntityManagerFactory( "openjpa" );
>
>        final Persister persister = new
> Persister( entityManagerFactory );
>        final Person person = new Person( "12345", "David Leangen" );
>        persister.createPerson( person );
>        final Collection<Person> people = persister.getAllPeople();
>        System.out.println("List of all people in db: ");
>        for( final Person nextDude: people )
>        {
>            System.out.println( nextDude.getName() );
>        }
>
>
> Thread.currentThread().setContextClassLoader( currentClassLoader );
>
>
> Persister code
> _______________________________________________
> package net.leangen.expedition.openjpa.internal;
>
> import java.util.*;
> import javax.persistence.*;
>
> public class Persister
> {
>        private final EntityManagerFactory entityManagerFactory;
>
>        public Persister( EntityManagerFactory anEntityManagerFactory )
>        {
>            entityManagerFactory = anEntityManagerFactory;
>        }
>
>        @SuppressWarnings("unchecked")
>    public Collection<Person> getAllPeople()
>        {
>            final EntityManager entityManager =
> entityManagerFactory.createEntityManager();
>                final EntityTransaction transaction =
> entityManager.getTransaction();
>                try
>                {
>                        transaction.begin();
>                        final List<Person> resultList =
> entityManager.createQuery( "select p
> from Persona p" ).getResultList();
>                        return resultList;
>                }
>                finally
>                {
>                        transaction.commit();
>                        entityManager.close();
>                }
>        }
>
>        public void createPerson( Person person )
>        {
>                final EntityManager entityManager =
> entityManagerFactory.createEntityManager();
>                final EntityTransaction transaction =
> entityManager.getTransaction();
>                try
>                {
>                        transaction.begin();
>                        entityManager.persist( person );
>                }
>                finally
>                {
>                        transaction.commit();
>                        entityManager.close();
>                }
>        }
> }
>
>
> pom.xml
> _______________________________________________
> <project>
>  ...
>
>  <build>
>    <plugins>
>      <plugin>
>        <groupId>org.codehaus.mojo</groupId>
>        <artifactId>openjpa-maven-plugin</artifactId>
>        <!-- use locally patched version for now -->
>        <version>1.1-SNAPSHOT</version>
>        <configuration>
>          <includes>src/main/java/**/*.class</includes>
>          <addDefaultConstructor>true</addDefaultConstructor>
>
> <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
>          <schemaAction>add</schemaAction>
>          <toolProperties>
>            <property>
>              <name>addDefaultConstructor</name>
>              <value>true</value>
>            </property>
>            <property>
>              <name>enforcePropertyRestrictions</name>
>              <value>true</value>
>            </property>
>            <property>
>              <name>properties</name>
>              <value>${basedir}/META-INF/persistence.xml</value>
>            </property>
>          </toolProperties>
>        </configuration>
>        <executions>
>          <execution>
>            <id>enhancer</id>
>            <phase>process-classes</phase>
>            <goals>
>              <goal>enhance</goal>
>            </goals>
>          </execution>
>        </executions>
>        <dependencies>
>          <dependency>
>            <groupId>org.apache.openjpa</groupId>
>            <artifactId>openjpa</artifactId>
>            <version>1.2.0</version>
>          </dependency>
>        </dependencies>
>      </plugin>
>    </plugins>
>  </build>
>
> </project>
>
>
> Exception
> _______________________________________________
> <openjpa-1.2.0-r422266:683325 fatal user error>
> org.apache.openjpa.persistence.ArgumentException: No table was given for
> persistent type "net.leangen.expedition.openjpa.internal.Person".
>         at
> org.apache.openjpa.jdbc.meta.MappingInfo.createTable(MappingInfo.java:437)
>        at
>
> org.apache.openjpa.jdbc.meta.ClassMappingInfo.getTable(ClassMappingInfo.java:241)
>        at
>
> org.apache.openjpa.jdbc.meta.ClassMappingInfo.getTable(ClassMappingInfo.java:259)
>        at
>
> org.apache.openjpa.jdbc.meta.strats.FullClassStrategy.map(FullClassStrategy.java:71)
>        at
>
> org.apache.openjpa.jdbc.meta.ClassMapping.setStrategy(ClassMapping.java:377)
>        at
>
> org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(RuntimeStrategyInstaller.java:55)
>        at
>
> org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRepository.java:333)
>        at
>
> org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository.java:662)
>        at
>
> org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:549)
>        at
>
> org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:308)
>        at
>
> org.apache.openjpa.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:285)
>        at
> org.apache.openjpa.jdbc.meta.MappingTool.getMapping(MappingTool.java:676)
>        at
> org.apache.openjpa.jdbc.meta.MappingTool.buildSchema(MappingTool.java:748)
>        at
> org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:646)
>        at
>
> org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:153)
>        at
>
> org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBrokerFactory.java:119)
>        at
>
> org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:189)
>        at
>
> org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
>        at
>
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
>        at
>
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:145)
>        at
>
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:56)
>        at
>
> net.leangen.expedition.openjpa.internal.Persister.createPerson(Persister.java:45)
>        at
> net.leangen.expedition.openjpa.internal.Activator.start(Activator.java:58)
>        at org.eclipse.osgi.framework.internal.core.BundleContextImpl
> $2.run(BundleContextImpl.java:1009)
>        at java.security.AccessController.doPrivileged(Native Method)
>        at
>
> org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:1003)
>        at
>
> org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:984)
>        at
>
> org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:346)
>        at
>
> org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:265)
>        at
>
> org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:257)
>        at
>
> org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._start(FrameworkCommandProvider.java:257)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>        at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>        at java.lang.reflect.Method.invoke(Method.java:585)
>        at
>
> org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCommandInterpreter.java:150)
>        at
>
> org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:302)
>        at
>
> org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(FrameworkConsole.java:287)
>        at
>
> org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(FrameworkConsole.java:223)
>        at java.lang.Thread.run(Thread.java:595)
>
>

Reply via email to