Open JPA error-Could not locate metadata for the class using alias

46 messages Options Options
Embed this Post
Permalink
1 2 3
Sai-2

Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink
Hi,
 
  I am trying to run standalone application access the database using spring ,openjpa.
 
  part of code in main method
 
  EntityManagerFactory factory = Persistence.createEntityManagerFactory("tsf");
        EntityManager em =  factory.createEntityManager();                
        System.out.println("------///// "+em);      
       
         
        Query q = em.createQuery("select m from AbstractItemEntity m");
        List<AbstractItemEntity> absEntity=q.getResultList();
 
  facing the problem at
        Query q = em.createQuery("select m from AbstractItemEntity m");
 
  we have persistance.xml and orm files.
 
  Log is as like below
  your earliest suggetions are valuable
 
  110  INFO   [main] openjpa.Runtime - Starting OpenJPA 0.9.6-incubating
  422  INFO   [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.OracleDictionary".
  766  INFO   [main] openjpa.MetaData - Found 10 classes with metadata in 31 milliseconds.
  ------///// org.apache.openjpa.persistence.EntityManagerImpl@1c8b24d
  Exception in thread "main" <4|true|0.9.6-incubating>  org.apache.openjpa.persistence.ArgumentException: Could not locate  metadata for the class using alias "AbstractItemEntity". Registered  alias mappings: "{AbstractItemEntity=null}"
      at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:343)
      at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getClassMetaData(JPQLExpressionBuilder.java:164)
      at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.resolveClassMetaData(JPQLExpressionBuilder.java:142)
      at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateMetaData(JPQLExpressionBuilder.java:211)
      at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateMetaData(JPQLExpressionBuilder.java:181)
      at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateType(JPQLExpressionBuilder.java:174)
      at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.access$500(JPQLExpressionBuilder.java:61)
      at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder$ParsedJPQL.populate(JPQLExpressionBuilder.java:1657)
      at org.apache.openjpa.kernel.jpql.JPQLParser.populate(JPQLParser.java:52)
      at org.apache.openjpa.kernel.ExpressionStoreQuery.populateFromCompilation(ExpressionStoreQuery.java:145)
      at org.apache.openjpa.kernel.QueryImpl.newCompilation(QueryImpl.java:642)
      at org.apache.openjpa.kernel.QueryImpl.compilationFromCache(QueryImpl.java:623)
      at org.apache.openjpa.kernel.QueryImpl.compileForCompilation(QueryImpl.java:589)
      at org.apache.openjpa.kernel.QueryImpl.compileForExecutor(QueryImpl.java:651)
      at org.apache.openjpa.kernel.QueryImpl.getOperation(QueryImpl.java:1464)
      at org.apache.openjpa.kernel.DelegatingQuery.getOperation(DelegatingQuery.java:120)
      at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:202)
      at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:251)
      at com.symcor.sis.tecp.dao.ExecuteDB.main(ExecuteDB.java:35)
 
 
       
---------------------------------
 Check out what you're missing if you're not on Yahoo! Messenger
Jacek Laskowski

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink
On 4/11/07, saidulu chitipolu <csai_india@...> wrote:

>   your earliest suggetions are valuable

You may want to take a look at the following thread -
http://www.mail-archive.com/open-jpa-dev@.../msg02770.html.

Make sure that your class is @Entity-annotated, PCEnhance it and put
the enhanced classes in the application classloader.

Consider sending the files - AbstractItemEntity.java and
persistence.xml and how you run the app - with javaagent or you
PCEnhance the entities.

Jacek

--
Jacek Laskowski
http://www.JacekLaskowski.pl
Pinaki Poddar-2

RE: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink
In reply to this post by Sai-2
Persistent Java classes when used in Query use an alias (which is, be
deafult, the unqualified name of the Java class). However, the alias is
known to the runtime once the Java class is loaded in to JVM. When the
very first JPA operation is a query and the persistence unit does not
explictly declare all the persistent classes, the runtime is not yet
aware of/registered the aliases. Hence the error.
possible resolution:
a) declare the persistent classes in <class> tag of persistence.xml
b) load the class before using it -- e.g. call
Class.forName("a.b.c.MyClass")

 
 


Pinaki Poddar
BEA Systems
415.402.7317  


-----Original Message-----
From: saidulu chitipolu [mailto:csai_india@...]
Sent: Wednesday, April 11, 2007 1:23 PM
To: open-jpa-dev@...
Subject: Open JPA error-Could not locate metadata for the class using
alias

Hi,
 
  I am trying to run standalone application access the database using
spring ,openjpa.
 
  part of code in main method
 
  EntityManagerFactory factory =
Persistence.createEntityManagerFactory("tsf");
        EntityManager em =  factory.createEntityManager();

        System.out.println("------///// "+em);      
       
         
        Query q = em.createQuery("select m from AbstractItemEntity m");
        List<AbstractItemEntity> absEntity=q.getResultList();
 
  facing the problem at
        Query q = em.createQuery("select m from AbstractItemEntity m");
 
  we have persistance.xml and orm files.
 
  Log is as like below
  your earliest suggetions are valuable
 
  110  INFO   [main] openjpa.Runtime - Starting OpenJPA 0.9.6-incubating
  422  INFO   [main] openjpa.jdbc.JDBC - Using dictionary class
"org.apache.openjpa.jdbc.sql.OracleDictionary".
  766  INFO   [main] openjpa.MetaData - Found 10 classes with metadata
in 31 milliseconds.
  ------///// org.apache.openjpa.persistence.EntityManagerImpl@1c8b24d
  Exception in thread "main" <4|true|0.9.6-incubating>
org.apache.openjpa.persistence.ArgumentException: Could not locate
metadata for the class using alias "AbstractItemEntity". Registered
alias mappings: "{AbstractItemEntity=null}"
      at
org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepositor
y.java:343)
      at
org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getClassMetaData(JP
QLExpressionBuilder.java:164)
      at
org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.resolveClassMetaDat
a(JPQLExpressionBuilder.java:142)
      at
org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateMetaDat
a(JPQLExpressionBuilder.java:211)
      at
org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateMetaDat
a(JPQLExpressionBuilder.java:181)
      at
org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateType(JP
QLExpressionBuilder.java:174)
      at
org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.access$500(JPQLExpr
essionBuilder.java:61)
      at
org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder$ParsedJPQL.populate
(JPQLExpressionBuilder.java:1657)
      at
org.apache.openjpa.kernel.jpql.JPQLParser.populate(JPQLParser.java:52)
      at
org.apache.openjpa.kernel.ExpressionStoreQuery.populateFromCompilation(E
xpressionStoreQuery.java:145)
      at
org.apache.openjpa.kernel.QueryImpl.newCompilation(QueryImpl.java:642)
      at
org.apache.openjpa.kernel.QueryImpl.compilationFromCache(QueryImpl.java:
623)
      at
org.apache.openjpa.kernel.QueryImpl.compileForCompilation(QueryImpl.java
:589)
      at
org.apache.openjpa.kernel.QueryImpl.compileForExecutor(QueryImpl.java:65
1)
      at
org.apache.openjpa.kernel.QueryImpl.getOperation(QueryImpl.java:1464)
      at
org.apache.openjpa.kernel.DelegatingQuery.getOperation(DelegatingQuery.j
ava:120)
      at
org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:202)
      at
org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:25
1)
      at com.symcor.sis.tecp.dao.ExecuteDB.main(ExecuteDB.java:35)
 
 
       
---------------------------------
 Check out what you're missing if you're not on Yahoo! Messenger

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.
Marina Vatkina

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink
Isn't it called an entity name in the JPA spec?

thanks,
-marina

Pinaki Poddar wrote:

> Persistent Java classes when used in Query use an alias (which is, be
> deafult, the unqualified name of the Java class). However, the alias is
> known to the runtime once the Java class is loaded in to JVM. When the
> very first JPA operation is a query and the persistence unit does not
> explictly declare all the persistent classes, the runtime is not yet
> aware of/registered the aliases. Hence the error.
> possible resolution:
> a) declare the persistent classes in <class> tag of persistence.xml
> b) load the class before using it -- e.g. call
> Class.forName("a.b.c.MyClass")
>
>  
>  
>
>
> Pinaki Poddar
> BEA Systems
> 415.402.7317  
>
>
> -----Original Message-----
> From: saidulu chitipolu [mailto:csai_india@...]
> Sent: Wednesday, April 11, 2007 1:23 PM
> To: open-jpa-dev@...
> Subject: Open JPA error-Could not locate metadata for the class using
> alias
>
> Hi,
>  
>   I am trying to run standalone application access the database using
> spring ,openjpa.
>  
>   part of code in main method
>  
>   EntityManagerFactory factory =
> Persistence.createEntityManagerFactory("tsf");
>         EntityManager em =  factory.createEntityManager();
>
>         System.out.println("------///// "+em);      
>        
>          
>         Query q = em.createQuery("select m from AbstractItemEntity m");
>         List<AbstractItemEntity> absEntity=q.getResultList();
>  
>   facing the problem at
>         Query q = em.createQuery("select m from AbstractItemEntity m");
>  
>   we have persistance.xml and orm files.
>  
>   Log is as like below
>   your earliest suggetions are valuable
>  
>   110  INFO   [main] openjpa.Runtime - Starting OpenJPA 0.9.6-incubating
>   422  INFO   [main] openjpa.jdbc.JDBC - Using dictionary class
> "org.apache.openjpa.jdbc.sql.OracleDictionary".
>   766  INFO   [main] openjpa.MetaData - Found 10 classes with metadata
> in 31 milliseconds.
>   ------///// org.apache.openjpa.persistence.EntityManagerImpl@1c8b24d
>   Exception in thread "main" <4|true|0.9.6-incubating>
> org.apache.openjpa.persistence.ArgumentException: Could not locate
> metadata for the class using alias "AbstractItemEntity". Registered
> alias mappings: "{AbstractItemEntity=null}"
>       at
> org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepositor
> y.java:343)
>       at
> org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getClassMetaData(JP
> QLExpressionBuilder.java:164)
>       at
> org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.resolveClassMetaDat
> a(JPQLExpressionBuilder.java:142)
>       at
> org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateMetaDat
> a(JPQLExpressionBuilder.java:211)
>       at
> org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateMetaDat
> a(JPQLExpressionBuilder.java:181)
>       at
> org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getCandidateType(JP
> QLExpressionBuilder.java:174)
>       at
> org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.access$500(JPQLExpr
> essionBuilder.java:61)
>       at
> org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder$ParsedJPQL.populate
> (JPQLExpressionBuilder.java:1657)
>       at
> org.apache.openjpa.kernel.jpql.JPQLParser.populate(JPQLParser.java:52)
>       at
> org.apache.openjpa.kernel.ExpressionStoreQuery.populateFromCompilation(E
> xpressionStoreQuery.java:145)
>       at
> org.apache.openjpa.kernel.QueryImpl.newCompilation(QueryImpl.java:642)
>       at
> org.apache.openjpa.kernel.QueryImpl.compilationFromCache(QueryImpl.java:
> 623)
>       at
> org.apache.openjpa.kernel.QueryImpl.compileForCompilation(QueryImpl.java
> :589)
>       at
> org.apache.openjpa.kernel.QueryImpl.compileForExecutor(QueryImpl.java:65
> 1)
>       at
> org.apache.openjpa.kernel.QueryImpl.getOperation(QueryImpl.java:1464)
>       at
> org.apache.openjpa.kernel.DelegatingQuery.getOperation(DelegatingQuery.j
> ava:120)
>       at
> org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:202)
>       at
> org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:25
> 1)
>       at com.symcor.sis.tecp.dao.ExecuteDB.main(ExecuteDB.java:35)
>  
>  
>        
> ---------------------------------
>  Check out what you're missing if you're not on Yahoo! Messenger
>
> Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.
tbee

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink
In reply to this post by Sai-2
I’m having the same exception. Strange is that the IDENTICAL codebase runs without errors under Toplink JPA. I’ve only changed the provider and properties in the persistence.xml and included the OpenJPA jars to the project. (That is what JPA should be able to do, afterall.)
Jacek Laskowski

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink
On 4/20/07, tbee <tbee@...> wrote:
>
> I'm having the same exception. Strange is that the IDENTICAL codebase runs
> without errors under Toplink JPA. I've only changed the provider and
> properties in the persistence.xml and included the OpenJPA jars to the
> project. (That is what JPA should be able to do, afterall.)

If a JPA provider runs in Java SE environments, persistence.xml file
should list all the available persistence classes using <class> to
insure portability.

The spec reads (6.2.1.6 mapping-file, jar-file, class,
exclude-unlisted-classes page 138):

"The class element is used to list a managed persistence class. A list
of all named managed persistence classes must be specified in Java SE
environments to insure portability. Portable Java SE applications
should not rely on the other mechanisms
described here to specify the managed persistence classes of a
persistence unit. Persistence providers may also require that the set
of entity classes and classes that are to be managed must be fully
enumerated in each of the persistence.xml files in Java SE
environments."

So I read it that you're relying "on the other mechanisms" TopLink JPA provides.

Jacek

--
Jacek Laskowski
http://www.JacekLaskowski.pl
tbee

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink

Jacek Laskowski-4 wrote:
So I read it that you're relying "on the other mechanisms" TopLink JPA provides.
Ah, no, all classes are defined in the persistence.xml. In fact I turned autodetection explicitely off when I was trying Hibernate (OpenJPA is attempt 3); my persistent classes are reverse engineered from the DB and some metatables generate classes that cause trouble, and I explicitely make them non-persistent by removing them from the <class> list. Sorry.
tbee

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink

tbee wrote:
Jacek Laskowski-4 wrote:
So I read it that you're relying "on the other mechanisms" TopLink JPA provides.
Ah, no, all classes are defined in the persistence.xml. In fact I turned autodetection explicitely off when I was trying Hibernate (OpenJPA is attempt 3); my persistent classes are reverse engineered from the DB and some metatables generate classes that cause trouble, and I explicitely make them non-persistent by removing them from the <class> list. Sorry.
Is it possible this has to do with the way I've setup the entity classes? What I do is have an @Entity class without any fields and it extends a @MappedSuperclass which is generated from the DB and where all the actual fields are declared.

package nl.reinders.bm;
@Entity
@Table(name="article")
public class Article extends nl.reinders.bm.generated.Article
{
        ... almost empty...
}


package nl.reinders.bm.generated;
@MappedSuperclass
public class Article
{
        @OneToMany(mappedBy = "iArticle"...
        ...
        @Column(name="description")
        private String iDescription;
        ....
}
Jacek Laskowski

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink
On 4/20/07, tbee <tbee@...> wrote:

> Is it possible this has to do with the way I've setup the entity classes?
> What I do is have an @Entity class without any fields and it extends a
> @MappedSuperclass which is generated from the DB and where all the actual
> fields are declared.

I've never used @MappedSuperclass so I can't comment on it. Could you
present your persistence.xml (and orm.xml if used)?

Jacek

--
Jacek Laskowski
http://www.JacekLaskowski.pl
tbee

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink

Jacek Laskowski-4 wrote:
I've never used @MappedSuperclass so I can't comment on it. Could you
present your persistence.xml (and orm.xml if used)?
Sure!

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
             version="1.0">

   <persistence-unit name="reinders">
               
                <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>

                <class>nl.reinders.bm.Contract</class>
....50x
                <class>nl.reinders.bm.Websort</class>

                <properties>
            <property name="openjpa.ConnectionDriverName" value="com.informix.jdbc.IfxDriver"/>
            <property name="openjpa.ConnectionURL" value="jdbc:informix-sqli://...;DB_LOCALE=en_us.utf8"/>
            <property name="openjpa.ConnectionUserName" value="user"/>
            <property name="openjpa.ConnectionPassword" value="password"/>
                </properties>
        </persistence-unit>
</persistence>
Jacek Laskowski

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink
On 4/20/07, tbee <tbee@...> wrote:

> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
>              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>              xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
>              version="1.0">
>
>    <persistence-unit name="reinders">
>
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>
>                 <class>nl.reinders.bm.Contract</class>
> ....50x
>                 <class>nl.reinders.bm.Websort</class>
>
>                 <properties>
>             <property name="openjpa.ConnectionDriverName"
> value="com.informix.jdbc.IfxDriver"/>
>             <property name="openjpa.ConnectionURL"
> value="jdbc:informix-sqli://...;DB_LOCALE=en_us.utf8"/>
>             <property name="openjpa.ConnectionUserName" value="user"/>
>             <property name="openjpa.ConnectionPassword" value="password"/>
>                 </properties>
>         </persistence-unit>
> </persistence>

Nothing relevant comes to my mind. Could you verify that your
application work when you add Class.forName() with each and every
entity after creating a PU, but before executing any queries? If that
should work, it might mean it's a OpenJPA bug.

Jacek

--
Jacek Laskowski
http://www.JacekLaskowski.pl
Marina Vatkina

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink
In reply to this post by tbee
The spec defines the following limitations of a MappedSuperclass:

2.1.9.2 Mapped Superclasses
...
A mapped superclass, unlike an entity, is not queryable and cannot be passed as
an argument to EntityManager or Query operations. A mapped superclass cannot be
the target of a persistent relationship.

-marina

tbee wrote:

>
>
> tbee wrote:
>
>>
>>
>>Jacek Laskowski-4 wrote:
>>
>>>So I read it that you're relying "on the other mechanisms" TopLink JPA
>>>provides.
>>>
>>
>>Ah, no, all classes are defined in the persistence.xml. In fact I turned
>>autodetection explicitely off when I was trying Hibernate (OpenJPA is
>>attempt 3); my persistent classes are reverse engineered from the DB and
>>some metatables generate classes that cause trouble, and I explicitely
>>make them non-persistent by removing them from the <class> list. Sorry.
>>
>
>
> Is it possible this has to do with the way I've setup the entity classes?
> What I do is have an @Entity class without any fields and it extends a
> @MappedSuperclass which is generated from the DB and where all the actual
> fields are declared.
>
> package nl.reinders.bm;
> @Entity
> @Table(name="article")
> public class Article extends nl.reinders.bm.generated.Article
> {
> ... almost empty...
> }
>
>
> package nl.reinders.bm.generated;
> @MappedSuperclass
> public class Article
> {
> @OneToMany(mappedBy = "iArticle"...
> ...
> @Column(name="description")
> private String iDescription;
> ....
> }
>

tbee

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink

Marina Vatkina wrote:
The spec defines the following limitations of a MappedSuperclass:

2.1.9.2 Mapped Superclasses
...
A mapped superclass, unlike an entity, is not queryable and cannot be passed as
an argument to EntityManager or Query operations. A mapped superclass cannot be
the target of a persistent relationship.
Correct. It is not. All relations refer to the inheriting classes. So even if the relation is defined in the @MappedSuperclass, the result of the relation are the actual @Entity.

I believe this approach is invaluable if you want to save coding time: my reverse engineering class generates a JPA MappedSuperclass based on the database and the actual Entity class only contains the JPA table annotation and all business logic.

Hibernate also has some trouble with this concept, but Toplink works fine. I have an issue with lazy loading there, but the approach is perfect.
Marina Vatkina

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink
tbee wrote:

>
>
> Marina Vatkina wrote:
>
>>The spec defines the following limitations of a MappedSuperclass:
>>
>>2.1.9.2 Mapped Superclasses
>>...
>>A mapped superclass, unlike an entity, is not queryable and cannot be
>>passed as
>>an argument to EntityManager or Query operations. A mapped superclass
>>cannot be
>>the target of a persistent relationship.
>>
>>
>
>
> Correct. It is not. All relations refer to the inheriting classes. So even
> if the relation is defined in the @MappedSuperclass, the result of the
> relation are the actual @Entity.

How can you define relationships in the mapped superclass that are *specified*
in terms of the entities?

>
> I believe this approach is invaluable if you want to save coding time: my
> reverse engineering class generates a JPA MappedSuperclass based on the
> database and the actual Entity class only contains the JPA table annotation
> and all business logic.

You can always change the annotation from @MappedSuperclass to an @Entity and
make the class abstract.

>
> Hibernate also has some trouble with this concept, but Toplink works fine. I
> have an issue with lazy loading there, but the approach is perfect.

They might, but that would be beyond the spec and as such not a portable solution.

>
tbee

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink
> How can you define relationships in the mapped superclass that are *specified*
> in terms of the entities?

Quite simple:

@Entity
class Article extends Article2

@MappedSuperclass
class Article2
  @ManyToOne
  private Manufacturer; // note: not Manufacturer2!!


> You can always change the annotation from @MappedSuperclass to an @Entity and
> make the class abstract.

I do not believe that will work. Aim of the game is that the class returned by queries, etc, must be the class containing all the business logic. So AFAIK that must be the @Entity. That class must extended a class that contains the reversed engineered mappings.


> They might, but that would be beyond the spec and as such not a portable solution.

If this is beyond the spec: what is @MappedSuperclass intended for?
Marina Vatkina

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink
tbee wrote:

>>How can you define relationships in the mapped superclass that are
>
> *specified*
>
>>in terms of the entities?
>
>
> Quite simple:
>
> @Entity
> class Article extends Article2
>
> @MappedSuperclass
> class Article2
>   @ManyToOne
>   private Manufacturer; // note: not Manufacturer2!!
>
>
>
>>You can always change the annotation from @MappedSuperclass to an @Entity
>>and
>>make the class abstract.
>
>
> I do not believe that will work. Aim of the game is that the class returned
> by queries, etc, must be the class containing all the business logic. So
> AFAIK that must be the @Entity. That class must extended a class that
> contains the reversed engineered mappings.

I didn't suggest to remove the existing @Entity annotation - what I suggested
was to change the @MappedSuperclass to be an @Entity, *and* make it *abstract*.
The latter will mean that you'll never get its instances back.


>
>
>
>>They might, but that would be beyond the spec and as such not a portable
>>solution.
>
>
> If this is beyond the spec: what is @MappedSuperclass intended for?

To share common fields between several entities without sharing the table that
they are mapped to. It's behavior is closer to that of an embeddable class and
the first version of the name that the expert group discussed had an
'embeddable' in its name (see A.4 Changes Since Public Draft "Renamed
EmbeddableSuperclass as MappedSuperclass.")

Regards,
-marina

>
tbee

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink

Marina Vatkina wrote:
I didn't suggest to remove the existing @Entity annotation - what I suggested
was to change the @MappedSuperclass to be an @Entity, *and* make it *abstract*.
The latter will mean that you'll never get its instances back.
Ok, do you mean:

 @Entity
 class Article extends Article2
 
 @Entity
abstract class Article2
   @ManyToOne
   private Manufacturer; // note: not Manufacturer2!!


Well, I'll give it a spin on, ah, tuesday. If it works and is better supported by frameworks, I'm all excited.

tbee

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink
In reply to this post by Marina Vatkina

Marina Vatkina wrote:
I didn't suggest to remove the existing @Entity annotation - what I suggested
was to change the @MappedSuperclass to be an @Entity, *and* make it *abstract*.
The latter will mean that you'll never get its instances back.
I've tested this, but OpenJPA still has the same error:

org.apache.openjpa.persistence.ArgumentException: Could not locate metadata for the class using alias "Article". Registered alias mappings: "{Article=null}"

As a comparison, Toplink does not accept this approach at all (@Entity extends @Entity). It requires the superclass to be MappedSuperclass (@Entity extends @MappedSuperclass).

So unforntunately this approach seems to be a dead end.

Marina Vatkina

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink
tbee wrote:

>
>
> Marina Vatkina wrote:
>
>>I didn't suggest to remove the existing @Entity annotation - what I
>>suggested
>>was to change the @MappedSuperclass to be an @Entity, *and* make it
>>*abstract*.
>>The latter will mean that you'll never get its instances back.
>>
>
>
> I've tested this, but OpenJPA still has the same error:
>
> org.apache.openjpa.persistence.ArgumentException: Could not locate metadata
> for the class using alias "Article". Registered alias mappings:
> "{Article=null}"
>
> As a comparison, Toplink does not accept this approach at all (@Entity
> extends @Entity). It requires the superclass to be MappedSuperclass (@Entity
> extends @MappedSuperclass).

This is close to impossible as there are probably CTS tests that use an @Entity
that extends another @Entity. Are you using JPA in an EE 5 container? Otherwise
you need to list all antities and mapped superclasses in your persistence.xml.

-marina

>
> So unforntunately this approach seems to be a dead end.
>
>

Craig L Russell

Re: Open JPA error-Could not locate metadata for the class using alias

Reply Threaded MoreMore options
Print post
Permalink
Hi tbee,

I've only seen bits and pieces of this issue scattered through a  
dozen emails. I understand vaguely that you're trying to separate the  
persistent field definition from the behavior, but can't really  
understand how you're trying to do it.

Would it be possible for you to post a complete (simple) example that  
shows what you are trying to do, including both the classes and the  
database schema, for both sides of the relationship.

Thanks,

Craig

On Apr 24, 2007, at 9:21 AM, Marina Vatkina wrote:

> tbee wrote:
>> Marina Vatkina wrote:
>>> I didn't suggest to remove the existing @Entity annotation - what I
>>> suggested was to change the @MappedSuperclass to be an @Entity,  
>>> *and* make it
>>> *abstract*.
>>> The latter will mean that you'll never get its instances back.
>>>
>> I've tested this, but OpenJPA still has the same error:
>> org.apache.openjpa.persistence.ArgumentException: Could not locate  
>> metadata
>> for the class using alias "Article". Registered alias mappings:
>> "{Article=null}"
>> As a comparison, Toplink does not accept this approach at all  
>> (@Entity
>> extends @Entity). It requires the superclass to be  
>> MappedSuperclass (@Entity
>> extends @MappedSuperclass).
>
> This is close to impossible as there are probably CTS tests that  
> use an @Entity
> that extends another @Entity. Are you using JPA in an EE 5  
> container? Otherwise you need to list all antities and mapped  
> superclasses in your persistence.xml.
>
> -marina
>
>> So unforntunately this approach seems to be a dead end.
>
Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@...
P.S. A good JDO? O, Gasp!



smime.p7s (3K) Download Attachment
1 2 3