You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by David Leangen <ko...@leangen.net> on 2009/03/26 07:53:27 UTC

No table was given for persistent type

Hello!

In an OSGi environment, I come across the exception below.

Why don't the default values work, I wonder?

I also tried explicitly using the @Table annotation, but I still get the
same error.

Probably, the error message is misleading somehow. Any ideas where I
should look?


Thank you!
=dml



<openjpa-1.2.0-r422266:683325 fatal user error>
org.apache.openjpa.persistence.ArgumentException: No table was given for
persistent type "TYPE".
	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)


Re: No table was given for persistent type

Posted by David Leangen <ko...@leangen.net>.
Beautiful!

Thank you very much. I am now able to work with this both within Eclipse
and without, thanks to your help as well as that of
org.apache.openjpa.lib.util.MultiClassLoader.


Cheers!
=David



On Fri, 2009-03-27 at 13:26 -0500, Kevin Sutter wrote:
> Use this project instead:  http://filebin.ca/dwjkxk/DavidLeangen.zip
> 
> On Fri, Mar 27, 2009 at 10:59 AM, Kevin Sutter <kw...@gmail.com> wrote:
> 
> > Okay, I couldn't resist...  I tried your source code and it worked for
> > me...  I did not use the maven plugin for building since I have maven 2.0.8
> > and it seems to require 2.0.6.  It also looks like you have a special
> > version of the plugin...  Anyway, I skipped the maven plugin.
> >
> > I created a simple Eclipse project with your Person and Persister classes.
> > I also created a PersonTest main test class.  I'm using openjpa 1.2.0.  I'm
> > using Postgres, like you have.
> >
> > I also modified your test slightly so that I wouldn't hit duplicate key.
> >
> > I ran it with both pre-enhancing the Person entity and by using the
> > -javaagent option.  Both of them worked.
> >
> > BTW, I found out that our sub-classing support will not even kick in if you
> > are using "final" types, so you're safe from that perspective.  You must be
> > enhancing somehow or else you would be getting an error message from the
> > sub-classing support.
> >
> > I posted my project here:  http://filebin.ca/zuquzp/DavidLeangen.zip
> >
> > You have the next move...  :-)
> > Kevin
> >
> >
> >
> > On Fri, Mar 27, 2009 at 9:42 AM, Kevin Sutter <kw...@gmail.com> wrote:
> >
> >> 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 <ko...@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)
> >>>
> >>>
> >>
> >


Re: No table was given for persistent type

Posted by Kevin Sutter <kw...@gmail.com>.
Use this project instead:  http://filebin.ca/dwjkxk/DavidLeangen.zip

On Fri, Mar 27, 2009 at 10:59 AM, Kevin Sutter <kw...@gmail.com> wrote:

> Okay, I couldn't resist...  I tried your source code and it worked for
> me...  I did not use the maven plugin for building since I have maven 2.0.8
> and it seems to require 2.0.6.  It also looks like you have a special
> version of the plugin...  Anyway, I skipped the maven plugin.
>
> I created a simple Eclipse project with your Person and Persister classes.
> I also created a PersonTest main test class.  I'm using openjpa 1.2.0.  I'm
> using Postgres, like you have.
>
> I also modified your test slightly so that I wouldn't hit duplicate key.
>
> I ran it with both pre-enhancing the Person entity and by using the
> -javaagent option.  Both of them worked.
>
> BTW, I found out that our sub-classing support will not even kick in if you
> are using "final" types, so you're safe from that perspective.  You must be
> enhancing somehow or else you would be getting an error message from the
> sub-classing support.
>
> I posted my project here:  http://filebin.ca/zuquzp/DavidLeangen.zip
>
> You have the next move...  :-)
> Kevin
>
>
>
> On Fri, Mar 27, 2009 at 9:42 AM, Kevin Sutter <kw...@gmail.com> wrote:
>
>> 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 <ko...@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)
>>>
>>>
>>
>

Re: No table was given for persistent type

Posted by Kevin Sutter <kw...@gmail.com>.
Okay, I couldn't resist...  I tried your source code and it worked for
me...  I did not use the maven plugin for building since I have maven 2.0.8
and it seems to require 2.0.6.  It also looks like you have a special
version of the plugin...  Anyway, I skipped the maven plugin.

I created a simple Eclipse project with your Person and Persister classes.
I also created a PersonTest main test class.  I'm using openjpa 1.2.0.  I'm
using Postgres, like you have.

I also modified your test slightly so that I wouldn't hit duplicate key.

I ran it with both pre-enhancing the Person entity and by using the
-javaagent option.  Both of them worked.

BTW, I found out that our sub-classing support will not even kick in if you
are using "final" types, so you're safe from that perspective.  You must be
enhancing somehow or else you would be getting an error message from the
sub-classing support.

I posted my project here:  http://filebin.ca/zuquzp/DavidLeangen.zip

You have the next move...  :-)
Kevin


On Fri, Mar 27, 2009 at 9:42 AM, Kevin Sutter <kw...@gmail.com> wrote:

> 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 <ko...@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)
>>
>>
>

Re: No table was given for persistent type

Posted by Kevin Sutter <kw...@gmail.com>.
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 <ko...@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)
>
>

Re: No table was given for persistent type

Posted by David Leangen <ko...@leangen.net>.
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)


Re: No table was given for persistent type

Posted by Kevin Sutter <kw...@gmail.com>.
Hi David,
I think we'll need a bit more information.  What do your Entities look
like?  What's in your persistence.xml file?  From the exception text, it
looks like you have an Entity with the name of "TYPE".  Is that accurate?
That may be reserved word, have you tried something like "TYPE1" just for
grins?  You also mention that the @Table annotation is not working, what
table name are you using in the @Table annotation?  Whether you are running
in an OSGI environment or not, this should be working for you.  Let us know
more details and we'll see if we can help you out.

Thanks,
Kevin

2009/3/26 David Leangen <ko...@leangen.net>

>
> Hello!
>
> In an OSGi environment, I come across the exception below.
>
> Why don't the default values work, I wonder?
>
> I also tried explicitly using the @Table annotation, but I still get the
> same error.
>
> Probably, the error message is misleading somehow. Any ideas where I
> should look?
>
>
> Thank you!
> =dml
>
>
>
> <openjpa-1.2.0-r422266:683325 fatal user error>
> org.apache.openjpa.persistence.ArgumentException: No table was given for
> persistent type "TYPE".
>        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)
>
>