Hello all.,

I am trying to test managed interfaces.

Getting the following exception, couldn't find any doc in the internet.

Exception in thread "main" java.lang.IllegalArgumentException: Invalid access 
type "invalid code 31" for "com.ejb.entity.Drivable".
        at 
org.apache.openjpa.meta.ClassMetaData.setAccessType(ClassMetaData.java:692)
        at 
org.apache.openjpa.meta.AbstractMetaDataDefaults.populate(AbstractMetaDataDefaults.java:156)
        at 
org.apache.openjpa.persistence.PersistenceMetaDataDefaults.populate(PersistenceMetaDataDefaults.java:257)
        at 
org.apache.openjpa.meta.MetaDataRepository.addMetaData(MetaDataRepository.java:883)
        at jpatesting.Main.main(Main.java:66)

//**** Code *******//
         EntityManagerFactory emf = 
Persistence.createEntityManagerFactory("jpatestingPU");
         EntityManager normalEm = emf.createEntityManager();
         Class c =  Class.forName("com.ejb.entity.Drivable");
         OpenJPAEntityManager em = OpenJPAPersistence.cast(normalEm);
         OpenJPAEntityManagerFactory factory =  em.getEntityManagerFactory();
         OpenJPAEntityManagerFactorySPI spi =  
(OpenJPAEntityManagerFactorySPI)factory;
         spi.getConfiguration().getMetaDataRepositoryInstance().register(c);
         ClassMetaData cmd =  
spi.getConfiguration().getMetaDataRepositoryInstance().addMetaData(c, 
ClassMetaData.MODE_ALL);
         cmd.setManagedInterface(true);
        Drivable d1=(Drivable)em.createInstance(c);
        System.out.println("Instance====>"+d1);
        d1.setName("Ford Mushtang");
        em.getTransaction().begin();
        em.persist(d1);
        em.getTransaction().commit();




________________________________
From: Michael Dick <[email protected]>
To: [email protected]
Sent: Wed, October 28, 2009 5:17:59 PM
Subject: Re: Problems with Interfaces

Hi Gopi,

The ManagedInterface annotation is intended to be used when you don't have a
concrete class. Instead OpenJPA will generate one for you [1]. Having a
concrete implementation might be contributing to your problem.

That said, I think the specific error you're hitting is the result of not
listing com.ejb.entity.FordMushtang in persistence.xml (along with
com.ejb.entity.Drivable).

If you provide a list of entity types those are the only ones that get
enhanced. Basically you should list all the classes you plan on using.

[1]
http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_pc_interfaces

Hope this helps,
-mike

On Wed, Oct 28, 2009 at 9:15 AM, shriram <[email protected]> wrote:

> Kevin,
>
> I just tried this as an example.
>
> Can you please let me know if something wrong in my assumption.
>
> @ManagedInterface
> interface Drivable
>
> class FordMushtang implements Drivable
>
> and my persistence.xml
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>     <class>com.ejb.entity.Drivable</class>
>
> <properties>
>      <property name="openjpa.RuntimeUnenhancedClasses" value="supported"/>
>    </properties>
>
> I am getting an exception of
>
> <openjpa-2.0.0-M3-r422266:822833 nonfatal user error>
> org.apache.openjpa.persistence.ArgumentException: Attempt to cast instance
> "com.ejb.entity.FordMushtang[id=234234234]" to PersistenceCapable failed.
>  Ensure that it has been enhanced.
> FailedObject: com.ejb.entity.FordMushtang[id=234234234]
>        at
> org.apache.openjpa.kernel.BrokerImpl.assertPersistenceCapable(BrokerImpl.java:4480)
>        at
> org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2505)
>        at
> org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2366)
>        at
> org.apache.openjpa.kernel.DelegatingBroker.persist(DelegatingBroker.java:1039)
>        at
> org.apache.openjpa.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:696)
>        at jpatesting.Main.persist(Main.java:85)
>        at jpatesting.Main.main(Main.java:66)
>
>
>
>
>
> ________________________________
> From: Kevin Sutter <[email protected]>
> To: [email protected]
> Sent: Wed, October 28, 2009 8:53:07 AM
> Subject: Re: Problems with Interfaces
>
> Hi Gopi,
>
> On Mon, Oct 26, 2009 at 6:10 PM, Gopi <[email protected]> wrote:
>
> >
> > > o  The @ManagedInterface "instances" are created by the runtime when
> you
> > > call createInstance(c).  You should not be defining a separate @Entity
> > > class.  This is like doubly defining your object model.
> > >
> > >
> >
> > Ok. I removed the @Entity from the class. So now in my persistence.xml,
> > instead of <class>EndpointObject</class>, I now have
> > <class>Endpoint</class>. Is this right?
> >
> > Yes, that's what I would expect.
>
>
> >
> > > o  To that end, your @GeneratedValue should be moved from your Entity
> > > class
> > > to your ManagedInterface interface.
> > >
> > >
> > Ok. Done.
> >
> > Good.
>
>
> > > o  And, it looks like you are doing a lot of extra processing with
> > > registration with the MetaDataRepository and ClassMetaData.  You should
> > > not
> > > have to mess around with these data structures.  After creating the
> > > instance
> > > and persisting it, the OpenJPA runtime should take care of the
> > > registration.
> > >
> > >
> >
> > The reason I am doing the extra processing is because, if I don't, I get
> > the
> > following error message. I found a solution to this in this forum at
> >
> >
> http://n2.nabble.com/Problem-using-OpenJPAEntityManager-createInstance-td1493116.html
> >
> >  [java] java.lang.IllegalArgumentException: No metadata was found for
> > managed interface Endpoint.
> >     [java]     at
> > org.apache.openjpa.kernel.BrokerImpl.newInstance(BrokerImpl.java:4319)
> >     [java]     at
> >
> >
> org.apache.openjpa.kernel.DelegatingBroker.newInstance(DelegatingBroker.java:1392)
> >     [java]     at
> >
> >
> org.apache.openjpa.persistence.EntityManagerImpl.createInstance(EntityManagerImpl.java:1243)
> >     [java]     at Main.main(Main.java:36)
> >
> > So how else do I get rid of this error message?
> >
>
> According to that post, this extra processing should not be necessary if
> you
> have included the ManagedInterface "entity" in the <class> element of
> persistence.xml.  So, even with the changes you did above, you are still
> getting this exception?
>
> From Pinaki's response...
>     "The metadata registration and classloading done in your code for
> managed interface *should* not be required if you specify the class name in
> <class> clause of persistence.xml. But please report if that is not the
> case."
>
>
> >
> > > o  One additional thought is how are you performing the enhancement
> > > processing [2]?  To be honest, I'm not entirely clear on how the
> > > @ManagedInterface instance creation integrates with our enhancement
> > > processing.  Maybe another developer can shed some light on this
> aspect.
> > >
> > >
> >
> > I am doing this by passing an arg to the jvm as follows in my build.xml
> > file.
> >
> > <target name="Main">
> >                <java classname="Main" failonerror="true" fork="yes">
> >                        <jvmarg
> > value="-javaagent:/Users/gopi/packages/openjpa/openjpa-all-2.0.0-M3.jar"
> />
> >                        <classpath refid="TestJPA1.classpath" />
> >                </java>
> > </target>
> >
>
> If you are only using @ManagedInterfaces and no other @Entities, then this
> should not even be required.  Pinaki's other reply on this thread has
> indicated that due to the generated byte-codes that we do for the
> @ManagedInterface instance creation, all of the enhancement processing is
> already done.  But, if you have other @Entities, then the use of the
> -javaagent is an easy way to get your Entities enhanced.
>
> Kevin
>
>
> > --
> > View this message in context:
> > http://n2.nabble.com/Problems-with-Interfaces-tp3894934p3895651.html
> > Sent from the OpenJPA Users mailing list archive at Nabble.com.
> >
>
>
>
>
>



      

Reply via email to