You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Igor Drobiazko <ig...@gmail.com> on 2011/07/12 17:15:15 UTC

Re: Problems accessing Named Queries in multiple Persistent Units

Looks like named query is not know in the BillingPUTest persistence unit.
How did you define it?

On Tue, Jul 12, 2011 at 2:19 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:

> I am using Tapestry 5.3 and the JPA module 5.3
>
> In my Page class:
>
>  @PersistenceContext(unitName = "BillingPUTest") private EntityManager em;
>
> @SuppressWarnings("unused")
>    @PageAttached
>    private void populate()
>    {
>    //   userList = facade.findAll();
>        // either variant will work the same
>       userList = em.createNamedQuery("Webusers.findAll",
> Webusers.class).getResultList();
>    }
>
> When I have only one persistent unit in persistence.xml, everything works,
> but once I add another unit (i.e. production database) I get the following
> exception:
>
> ava.lang.RuntimeException
> Unable to attach page TapPage: NamedQuery of name: Webusers.findAll not
> found.
> java.lang.IllegalArgumentException
> NamedQuery of name: Webusers.findAll not found.
> Hide uninteresting stack framesStack trace
>
> org.eclipse.persistence.internal.jpa.EJBQueryImpl.getDatabaseQueryInternal(EJBQueryImpl.java:576)
>
> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1004)
>
> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1024)
> com.baw.website.pages.TapPage.populate(TapPage.java:25)
> com.baw.website.pages.TapPage.populate$access122fbc563a57e270(TapPage.java)
> com.baw.website.pages.TapPage$Shim_122fbc563a57e26f.invoke(Unknown Source)
>
> org.apache.tapestry5.internal.plastic.MethodHandleImpl.invoke(MethodHandleImpl.java:48)
> It also works every time from a session bean, just not from an EM injected
> into the tapestry page.
>
> Please help!
>
>


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de

Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
Never mind this, I actually will have multiple different databases that this app accesses in the future,
so multiple PUs are here to stay.

On Jul 12, 2011, at 2:13 PM, Lenny Primak wrote:

> Thanks Igor!
> Perhaps I am not doing things the optimal way.
> My use case is that I have a production and a development database.
> I would like to have the same war file for both, and depending on system properties,
> choose what database to access.
> I have Persistence Unit for the production and one for the development database,
> which I choose at runtime.
> 
> Is there a better way to do this?
> 
> On Jul 12, 2011, at 2:09 PM, Igor Drobiazko wrote:
> 
>> Hi Lenny,
>> 
>> the JpaEntityPackageManager service is invoked if only a single persistence
>> unit is defined. The reasons are:
>> 
>> 1) 99% of the apps are using a single persistence unit. In this
>> case, auto-configuring entities from the entities su-package is very
>> useful.
>> 2) if multiple persistence units are defined, Tapestry doesn't know where to
>> add the entities.
>> 
>> The documentations mentions that. Maybe it should be emphasized a little bit
>> more.
>> 
>> So, you need to contribute a PersistenceUnitConfigurer to the
>> EntityManagerSource service's configuration.
>> 
>> 
>> On Tue, Jul 12, 2011 at 7:00 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:
>> 
>>> I use persistense.xml.
>>> 
>>> I don't think  @Contribute(JpaEntityPackageManager.class)    public static
>>> void providePackages(Configuration<String> configuration)
>>> is getting called, hence continuing of my frustrations.
>>> Still need help with getting that resolved.
>>> 
>>> Thanks!
>>> 
>>> Here is my persistense.xml:
>>> ----------------
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <persistence version="2.0" 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_2_0.xsd">
>>> <persistence-unit name="BillingPUTest" transaction-type="JTA">
>>>  <jta-data-source>jdbc/BillingTest</jta-data-source>
>>>  <exclude-unlisted-classes>false</exclude-unlisted-classes>
>>>  <properties/>
>>> </persistence-unit>
>>> 
>>> <persistence-unit name="BillingPUProd" transaction-type="JTA">
>>>  <jta-data-source>jdbc/BillingProd</jta-data-source>
>>>  <exclude-unlisted-classes>false</exclude-unlisted-classes>
>>>  <properties/>
>>> </persistence-unit>
>>> </persistence>
>>> 
>>> 
>>> On Jul 12, 2011, at 11:15 AM, Igor Drobiazko wrote:
>>> 
>>>> Looks like named query is not know in the BillingPUTest persistence unit.
>>>> How did you define it?
>>>> 
>>>> On Tue, Jul 12, 2011 at 2:19 PM, Lenny Primak <lprimak@hope.nyc.ny.us
>>>> wrote:
>>>> 
>>>>> I am using Tapestry 5.3 and the JPA module 5.3
>>>>> 
>>>>> In my Page class:
>>>>> 
>>>>> @PersistenceContext(unitName = "BillingPUTest") private EntityManager
>>> em;
>>>>> 
>>>>> @SuppressWarnings("unused")
>>>>> @PageAttached
>>>>> private void populate()
>>>>> {
>>>>> //   userList = facade.findAll();
>>>>>     // either variant will work the same
>>>>>    userList = em.createNamedQuery("Webusers.findAll",
>>>>> Webusers.class).getResultList();
>>>>> }
>>>>> 
>>>>> When I have only one persistent unit in persistence.xml, everything
>>> works,
>>>>> but once I add another unit (i.e. production database) I get the
>>> following
>>>>> exception:
>>>>> 
>>>>> ava.lang.RuntimeException
>>>>> Unable to attach page TapPage: NamedQuery of name: Webusers.findAll not
>>>>> found.
>>>>> java.lang.IllegalArgumentException
>>>>> NamedQuery of name: Webusers.findAll not found.
>>>>> Hide uninteresting stack framesStack trace
>>>>> 
>>>>> 
>>> org.eclipse.persistence.internal.jpa.EJBQueryImpl.getDatabaseQueryInternal(EJBQueryImpl.java:576)
>>>>> 
>>>>> 
>>> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1004)
>>>>> 
>>>>> 
>>> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1024)
>>>>> com.baw.website.pages.TapPage.populate(TapPage.java:25)
>>>>> 
>>> com.baw.website.pages.TapPage.populate$access122fbc563a57e270(TapPage.java)
>>>>> com.baw.website.pages.TapPage$Shim_122fbc563a57e26f.invoke(Unknown
>>> Source)
>>>>> 
>>>>> 
>>> org.apache.tapestry5.internal.plastic.MethodHandleImpl.invoke(MethodHandleImpl.java:48)
>>>>> It also works every time from a session bean, just not from an EM
>>> injected
>>>>> into the tapestry page.
>>>>> 
>>>>> Please help!
>>>>> 
>>>>> 
>>>> 
>>>> 
>>>> --
>>>> Best regards,
>>>> 
>>>> Igor Drobiazko
>>>> http://tapestry5.de
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>> 
>>> 
>> 
>> 
>> -- 
>> Best regards,
>> 
>> Igor Drobiazko
>> http://tapestry5.de
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
Thanks Igor!
Perhaps I am not doing things the optimal way.
My use case is that I have a production and a development database.
I would like to have the same war file for both, and depending on system properties,
choose what database to access.
I have Persistence Unit for the production and one for the development database,
which I choose at runtime.

Is there a better way to do this?

On Jul 12, 2011, at 2:09 PM, Igor Drobiazko wrote:

> Hi Lenny,
> 
> the JpaEntityPackageManager service is invoked if only a single persistence
> unit is defined. The reasons are:
> 
> 1) 99% of the apps are using a single persistence unit. In this
> case, auto-configuring entities from the entities su-package is very
> useful.
> 2) if multiple persistence units are defined, Tapestry doesn't know where to
> add the entities.
> 
> The documentations mentions that. Maybe it should be emphasized a little bit
> more.
> 
> So, you need to contribute a PersistenceUnitConfigurer to the
> EntityManagerSource service's configuration.
> 
> 
> On Tue, Jul 12, 2011 at 7:00 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:
> 
>> I use persistense.xml.
>> 
>> I don't think  @Contribute(JpaEntityPackageManager.class)    public static
>> void providePackages(Configuration<String> configuration)
>> is getting called, hence continuing of my frustrations.
>> Still need help with getting that resolved.
>> 
>> Thanks!
>> 
>> Here is my persistense.xml:
>> ----------------
>> <?xml version="1.0" encoding="UTF-8"?>
>> <persistence version="2.0" 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_2_0.xsd">
>> <persistence-unit name="BillingPUTest" transaction-type="JTA">
>>   <jta-data-source>jdbc/BillingTest</jta-data-source>
>>   <exclude-unlisted-classes>false</exclude-unlisted-classes>
>>   <properties/>
>> </persistence-unit>
>> 
>> <persistence-unit name="BillingPUProd" transaction-type="JTA">
>>   <jta-data-source>jdbc/BillingProd</jta-data-source>
>>   <exclude-unlisted-classes>false</exclude-unlisted-classes>
>>   <properties/>
>> </persistence-unit>
>> </persistence>
>> 
>> 
>> On Jul 12, 2011, at 11:15 AM, Igor Drobiazko wrote:
>> 
>>> Looks like named query is not know in the BillingPUTest persistence unit.
>>> How did you define it?
>>> 
>>> On Tue, Jul 12, 2011 at 2:19 PM, Lenny Primak <lprimak@hope.nyc.ny.us
>>> wrote:
>>> 
>>>> I am using Tapestry 5.3 and the JPA module 5.3
>>>> 
>>>> In my Page class:
>>>> 
>>>> @PersistenceContext(unitName = "BillingPUTest") private EntityManager
>> em;
>>>> 
>>>> @SuppressWarnings("unused")
>>>>  @PageAttached
>>>>  private void populate()
>>>>  {
>>>>  //   userList = facade.findAll();
>>>>      // either variant will work the same
>>>>     userList = em.createNamedQuery("Webusers.findAll",
>>>> Webusers.class).getResultList();
>>>>  }
>>>> 
>>>> When I have only one persistent unit in persistence.xml, everything
>> works,
>>>> but once I add another unit (i.e. production database) I get the
>> following
>>>> exception:
>>>> 
>>>> ava.lang.RuntimeException
>>>> Unable to attach page TapPage: NamedQuery of name: Webusers.findAll not
>>>> found.
>>>> java.lang.IllegalArgumentException
>>>> NamedQuery of name: Webusers.findAll not found.
>>>> Hide uninteresting stack framesStack trace
>>>> 
>>>> 
>> org.eclipse.persistence.internal.jpa.EJBQueryImpl.getDatabaseQueryInternal(EJBQueryImpl.java:576)
>>>> 
>>>> 
>> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1004)
>>>> 
>>>> 
>> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1024)
>>>> com.baw.website.pages.TapPage.populate(TapPage.java:25)
>>>> 
>> com.baw.website.pages.TapPage.populate$access122fbc563a57e270(TapPage.java)
>>>> com.baw.website.pages.TapPage$Shim_122fbc563a57e26f.invoke(Unknown
>> Source)
>>>> 
>>>> 
>> org.apache.tapestry5.internal.plastic.MethodHandleImpl.invoke(MethodHandleImpl.java:48)
>>>> It also works every time from a session bean, just not from an EM
>> injected
>>>> into the tapestry page.
>>>> 
>>>> Please help!
>>>> 
>>>> 
>>> 
>>> 
>>> --
>>> Best regards,
>>> 
>>> Igor Drobiazko
>>> http://tapestry5.de
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
>> 
> 
> 
> -- 
> Best regards,
> 
> Igor Drobiazko
> http://tapestry5.de


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
My PUs are statically defined, and they are both development and production PUs available,
but only one is accessed at any one time depending on which app server the app is installed.
This is actually only one aspect, as this app does access multiple databases.

On Jul 12, 2011, at 4:04 PM, Kalle Korhonen wrote:

> On Tue, Jul 12, 2011 at 12:53 PM, Lenny Primak <lp...@hope.nyc.ny.us> wrote:
>> About scanning all packages, in my situation there is production and development databases,
>> they have exactly the same schema, so in this instance scanning all packages is the right thing to do,
>> but I would be very happy with contributePackages() working in case of multiple PUs.
>> That's documented well and easy to set up.
> 
> Sorry, just following from the sidelines but shouldn't you only have
> one persistence unit available at a time in that case? At least that's
> what I do with a similar (development/production environment)
> Hibernate-based set-up.
> 
> Kalle
> 
> 
>> On Jul 12, 2011, at 3:47 PM, Igor Drobiazko wrote:
>> 
>>> On Tue, Jul 12, 2011 at 9:24 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:
>>> 
>>>> Thanks again Igor,
>>>> Unfortunately, we have other parts of the app using persistence.xml,
>>>> so this isn't a great solution.
>>>> I don't really see a way to do this cleanly with this method.
>>>> 
>>> 
>>> You can still have a persistence.xml file. A PersistenceUnitConfigurer may
>>> be contributed to configure a persistence unit from scratch (without
>>> persistence.xml) or to modify the information read from persistence.xml. So,
>>> you just need to
>>> 
>>>> 
>>>> May I suggest the following patch:
>>>> EntityManagerSourceImpl.java,
>>>> 
>>>> ------------- instead of ------------
>>>> if(persistenceUnitInfos.size() == 1)
>>>> 
>>>> packageNamePersistenceUnitConfigurer.configure(persistenceUnitInfos.get(0));
>>>> -------
>>>> just call packageNamePersistenceUnitConfigurer.configure() for all the PUs.
>>>> 
>>> 
>>> Scanning the classpath for the entities (if multiple units are present) and
>>> adding them to all the available persistence units doesn't make sense. Does
>>> it?  Why would you provide several persistence units if they all are have
>>> the same set of entities? Wouldn't it cause data inconsistency issues?
>>> 
>>> 
>>> 
>>>> I don't see this causing any harm and will fix my problem in an instant.
>>>> 
>>>> 
>>>> On Jul 12, 2011, at 3:08 PM, Igor Drobiazko wrote:
>>>> 
>>>>> On Tue, Jul 12, 2011 at 9:02 PM, Lenny Primak <lprimak@hope.nyc.ny.us
>>>>> wrote:
>>>>> 
>>>>>> I'm having trouble figuring this out.  Can you help me so I can go on a
>>>>>> well deserved vacation?
>>>>>> 
>>>>> 
>>>>> I wasn't fast enough since your last mail :) Please checkout the
>>>> "XML-less
>>>>> JPA configuration" section at the following page.
>>>>> 
>>>>> http://tapestry.apache.org/integrating-with-jpa.html
>>>>> 
>>>>> On that page you will find an example of a contribution to the
>>>>> EntityManagerSource service. The passed TapestryPersistenceUnitInfo
>>>> instance
>>>>> can be used to add managed classes.
>>>>> 
>>>>> 
>>>>>> BTW your book is fantastic!
>>>>>> 
>>>>>> 
>>>>> Thank you.
>>>>> 
>>>>> BTW your feedback on the JPA integration is very much appreciated.
>>>> Tapestry
>>>>> 5.3 is alpha now. Thanks for using it and providing very valuable
>>>> feedback.
>>>>> 
>>>>> --
>>>>> Best regards,
>>>>> 
>>>>> Igor Drobiazko
>>>>> http://tapestry5.de
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>> 
>>>> 
>>> 
>>> 
>>> --
>>> Best regards,
>>> 
>>> Igor Drobiazko
>>> http://tapestry5.de
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Kalle Korhonen <ka...@gmail.com>.
On Tue, Jul 12, 2011 at 12:53 PM, Lenny Primak <lp...@hope.nyc.ny.us> wrote:
> About scanning all packages, in my situation there is production and development databases,
> they have exactly the same schema, so in this instance scanning all packages is the right thing to do,
> but I would be very happy with contributePackages() working in case of multiple PUs.
> That's documented well and easy to set up.

Sorry, just following from the sidelines but shouldn't you only have
one persistence unit available at a time in that case? At least that's
what I do with a similar (development/production environment)
Hibernate-based set-up.

Kalle


> On Jul 12, 2011, at 3:47 PM, Igor Drobiazko wrote:
>
>> On Tue, Jul 12, 2011 at 9:24 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:
>>
>>> Thanks again Igor,
>>> Unfortunately, we have other parts of the app using persistence.xml,
>>> so this isn't a great solution.
>>> I don't really see a way to do this cleanly with this method.
>>>
>>
>> You can still have a persistence.xml file. A PersistenceUnitConfigurer may
>> be contributed to configure a persistence unit from scratch (without
>> persistence.xml) or to modify the information read from persistence.xml. So,
>> you just need to
>>
>>>
>>> May I suggest the following patch:
>>> EntityManagerSourceImpl.java,
>>>
>>> ------------- instead of ------------
>>> if(persistenceUnitInfos.size() == 1)
>>>
>>> packageNamePersistenceUnitConfigurer.configure(persistenceUnitInfos.get(0));
>>> -------
>>> just call packageNamePersistenceUnitConfigurer.configure() for all the PUs.
>>>
>>
>> Scanning the classpath for the entities (if multiple units are present) and
>> adding them to all the available persistence units doesn't make sense. Does
>> it?  Why would you provide several persistence units if they all are have
>> the same set of entities? Wouldn't it cause data inconsistency issues?
>>
>>
>>
>>> I don't see this causing any harm and will fix my problem in an instant.
>>>
>>>
>>> On Jul 12, 2011, at 3:08 PM, Igor Drobiazko wrote:
>>>
>>>> On Tue, Jul 12, 2011 at 9:02 PM, Lenny Primak <lprimak@hope.nyc.ny.us
>>>> wrote:
>>>>
>>>>> I'm having trouble figuring this out.  Can you help me so I can go on a
>>>>> well deserved vacation?
>>>>>
>>>>
>>>> I wasn't fast enough since your last mail :) Please checkout the
>>> "XML-less
>>>> JPA configuration" section at the following page.
>>>>
>>>> http://tapestry.apache.org/integrating-with-jpa.html
>>>>
>>>> On that page you will find an example of a contribution to the
>>>> EntityManagerSource service. The passed TapestryPersistenceUnitInfo
>>> instance
>>>> can be used to add managed classes.
>>>>
>>>>
>>>>> BTW your book is fantastic!
>>>>>
>>>>>
>>>> Thank you.
>>>>
>>>> BTW your feedback on the JPA integration is very much appreciated.
>>> Tapestry
>>>> 5.3 is alpha now. Thanks for using it and providing very valuable
>>> feedback.
>>>>
>>>> --
>>>> Best regards,
>>>>
>>>> Igor Drobiazko
>>>> http://tapestry5.de
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>
>>
>> --
>> Best regards,
>>
>> Igor Drobiazko
>> http://tapestry5.de
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Igor Drobiazko <ig...@gmail.com>.
I started a discussion in the developers list. Feel free to join.

On Tue, Jul 12, 2011 at 10:48 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:

> Since I have persistence.xml, it didn't even occur to me that I needed
> configure it manually,
> and the documentation only shows how to do it for a new programmatic PU.
> So, without knowing that I needed to do this, it was next to impossible to
> figure out what's going on here.
> Also, the relationships between entity packages and entity classes isn't at
> all clear.
>
> I think there should be a paragraph in the documentation stating clearly
> that if you
> have multiple PUs in persistence.xml, this is what needs to be done, and a
> code snippet.
>
> Once again thanks for all your help, no more all-nighters for me :)
>
> On Jul 12, 2011, at 4:36 PM, Igor Drobiazko wrote:
>
> > On Tue, Jul 12, 2011 at 10:28 PM, Lenny Primak <lprimak@hope.nyc.ny.us
> >wrote:
> >
> >> Thank you!  That finally worked.
> >>
> >
> > Great.
> >
> >>
> >> Definitely not trivial to figure out...
> >>
> >
> > Well, actually the documentation mentions how to configure persistence
> units
> > programmatically.
> >
> > http://tapestry.apache.org/integrating-with-jpa.html
> >
> > However, comments on improving the doc are welcome.
> >
> >
> >> Here is the code if anybody is interested:
> >>
> >
> > BTW: The if-check in your code is not needed, as you associate the
> > configurer with the unit using:
> >
> > configuration.add(DBConstants.BILLING_PU, configurer);
> >
> >
> >> -----------------------------------------
> >>   @Contribute(EntityManagerSource.class)
> >>   public static void configurePUs(
> >>           final MappedConfiguration<String, PersistenceUnitConfigurer>
> >> configuration, final ClassNameLocator locator)
> >>   {
> >>       final PersistenceUnitConfigurer configurer = new
> >> PersistenceUnitConfigurer()
> >>       {
> >>           @Override
> >>           public void configure(final TapestryPersistenceUnitInfo
> >> unitInfo)
> >>           {
> >>               if
> >> (unitInfo.getPersistenceUnitName().equals(DBConstants.BILLING_PU))
> >>               {
> >>                   for (String className :
> >> locator.locateClassNames("com.baw.website.entities"))
> >>                   {
> >>                       unitInfo.addManagedClassName(className);
> >>                   }
> >>               }
> >>           }
> >>       };
> >>       configuration.add(DBConstants.BILLING_PU, configurer);
> >>   }
> >> -----------------------
> >>
> >> On Jul 12, 2011, at 4:06 PM, Igor Drobiazko wrote:
> >>
> >>> On Tue, Jul 12, 2011 at 9:53 PM, Lenny Primak <lprimak@hope.nyc.ny.us
> >>> wrote:
> >>>
> >>>> I've been trying to figure out how to add package name to an existing
> PU
> >>>> read from persistence.xml,
> >>>> can you share some code on how to do that?  That would work for me
> just
> >>>> fine.
> >>>> I am unable to figure that out.
> >>>>
> >>>
> >>> Check out this module:
> >>>
> >>>
> >>
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app1/services/AppModule.java?view=markup
> >>>
> >>> The persistence units read from persistence.xml are edited by adding
> >> managed
> >>> classes.
> >>>
> >>>
> >>>>
> >>>> About scanning all packages, in my situation there is production and
> >>>> development databases,
> >>>> they have exactly the same schema, so in this instance scanning all
> >>>> packages is the right thing to do,
> >>>>
> >>>
> >>> So, actually you have a single persistence unit which connects to
> >> different
> >>> databases based on the current environment. Right? In this case you
> could
> >>> override the location of the test persistence descriptor, as here:
> >>>
> >>>   @Contribute(SymbolProvider.class)
> >>>   @ApplicationDefaults
> >>>   public static void provideFactoryDefaults(
> >>>           final MappedConfiguration<String, String> configuration)
> >>>   {
> >>>       configuration.add(JpaSymbols.PERSISTENCE_DESCRIPTOR,
> >>> "/single-persistence-unit.xml");
> >>>   }
> >>>
> >>>
> >>>
> >>>> but I would be very happy with contributePackages() working in case of
> >>>> multiple PUs.
> >>>> That's documented well and easy to set up.
> >>>> Thanks again!
> >>>>
> >>>>
> >>>> On Jul 12, 2011, at 3:47 PM, Igor Drobiazko wrote:
> >>>>
> >>>>> On Tue, Jul 12, 2011 at 9:24 PM, Lenny Primak <
> lprimak@hope.nyc.ny.us
> >>>>> wrote:
> >>>>>
> >>>>>> Thanks again Igor,
> >>>>>> Unfortunately, we have other parts of the app using persistence.xml,
> >>>>>> so this isn't a great solution.
> >>>>>> I don't really see a way to do this cleanly with this method.
> >>>>>>
> >>>>>
> >>>>> You can still have a persistence.xml file. A
> PersistenceUnitConfigurer
> >>>> may
> >>>>> be contributed to configure a persistence unit from scratch (without
> >>>>> persistence.xml) or to modify the information read from
> >> persistence.xml.
> >>>> So,
> >>>>> you just need to
> >>>>>
> >>>>>>
> >>>>>> May I suggest the following patch:
> >>>>>> EntityManagerSourceImpl.java,
> >>>>>>
> >>>>>> ------------- instead of ------------
> >>>>>> if(persistenceUnitInfos.size() == 1)
> >>>>>>
> >>>>>>
> >>>>
> >>
> packageNamePersistenceUnitConfigurer.configure(persistenceUnitInfos.get(0));
> >>>>>> -------
> >>>>>> just call packageNamePersistenceUnitConfigurer.configure() for all
> the
> >>>> PUs.
> >>>>>>
> >>>>>
> >>>>> Scanning the classpath for the entities (if multiple units are
> present)
> >>>> and
> >>>>> adding them to all the available persistence units doesn't make
> sense.
> >>>> Does
> >>>>> it?  Why would you provide several persistence units if they all are
> >> have
> >>>>> the same set of entities? Wouldn't it cause data inconsistency
> issues?
> >>>>>
> >>>>>
> >>>>>
> >>>>>> I don't see this causing any harm and will fix my problem in an
> >> instant.
> >>>>>>
> >>>>>>
> >>>>>> On Jul 12, 2011, at 3:08 PM, Igor Drobiazko wrote:
> >>>>>>
> >>>>>>> On Tue, Jul 12, 2011 at 9:02 PM, Lenny Primak <
> >> lprimak@hope.nyc.ny.us
> >>>>>>> wrote:
> >>>>>>>
> >>>>>>>> I'm having trouble figuring this out.  Can you help me so I can go
> >> on
> >>>> a
> >>>>>>>> well deserved vacation?
> >>>>>>>>
> >>>>>>>
> >>>>>>> I wasn't fast enough since your last mail :) Please checkout the
> >>>>>> "XML-less
> >>>>>>> JPA configuration" section at the following page.
> >>>>>>>
> >>>>>>> http://tapestry.apache.org/integrating-with-jpa.html
> >>>>>>>
> >>>>>>> On that page you will find an example of a contribution to the
> >>>>>>> EntityManagerSource service. The passed TapestryPersistenceUnitInfo
> >>>>>> instance
> >>>>>>> can be used to add managed classes.
> >>>>>>>
> >>>>>>>
> >>>>>>>> BTW your book is fantastic!
> >>>>>>>>
> >>>>>>>>
> >>>>>>> Thank you.
> >>>>>>>
> >>>>>>> BTW your feedback on the JPA integration is very much appreciated.
> >>>>>> Tapestry
> >>>>>>> 5.3 is alpha now. Thanks for using it and providing very valuable
> >>>>>> feedback.
> >>>>>>>
> >>>>>>> --
> >>>>>>> Best regards,
> >>>>>>>
> >>>>>>> Igor Drobiazko
> >>>>>>> http://tapestry5.de
> >>>>>>
> >>>>>>
> >>>>>>
> ---------------------------------------------------------------------
> >>>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >>>>>> For additional commands, e-mail: users-help@tapestry.apache.org
> >>>>>>
> >>>>>>
> >>>>>
> >>>>>
> >>>>> --
> >>>>> Best regards,
> >>>>>
> >>>>> Igor Drobiazko
> >>>>> http://tapestry5.de
> >>>>
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >>>> For additional commands, e-mail: users-help@tapestry.apache.org
> >>>>
> >>>>
> >>>
> >>>
> >>> --
> >>> Best regards,
> >>>
> >>> Igor Drobiazko
> >>> http://tapestry5.de
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
> >
> >
> > --
> > Best regards,
> >
> > Igor Drobiazko
> > http://tapestry5.de
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de

Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
Since I have persistence.xml, it didn't even occur to me that I needed configure it manually,
and the documentation only shows how to do it for a new programmatic PU.
So, without knowing that I needed to do this, it was next to impossible to figure out what's going on here.
Also, the relationships between entity packages and entity classes isn't at all clear.

I think there should be a paragraph in the documentation stating clearly that if you
have multiple PUs in persistence.xml, this is what needs to be done, and a code snippet.

Once again thanks for all your help, no more all-nighters for me :)

On Jul 12, 2011, at 4:36 PM, Igor Drobiazko wrote:

> On Tue, Jul 12, 2011 at 10:28 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:
> 
>> Thank you!  That finally worked.
>> 
> 
> Great.
> 
>> 
>> Definitely not trivial to figure out...
>> 
> 
> Well, actually the documentation mentions how to configure persistence units
> programmatically.
> 
> http://tapestry.apache.org/integrating-with-jpa.html
> 
> However, comments on improving the doc are welcome.
> 
> 
>> Here is the code if anybody is interested:
>> 
> 
> BTW: The if-check in your code is not needed, as you associate the
> configurer with the unit using:
> 
> configuration.add(DBConstants.BILLING_PU, configurer);
> 
> 
>> -----------------------------------------
>>   @Contribute(EntityManagerSource.class)
>>   public static void configurePUs(
>>           final MappedConfiguration<String, PersistenceUnitConfigurer>
>> configuration, final ClassNameLocator locator)
>>   {
>>       final PersistenceUnitConfigurer configurer = new
>> PersistenceUnitConfigurer()
>>       {
>>           @Override
>>           public void configure(final TapestryPersistenceUnitInfo
>> unitInfo)
>>           {
>>               if
>> (unitInfo.getPersistenceUnitName().equals(DBConstants.BILLING_PU))
>>               {
>>                   for (String className :
>> locator.locateClassNames("com.baw.website.entities"))
>>                   {
>>                       unitInfo.addManagedClassName(className);
>>                   }
>>               }
>>           }
>>       };
>>       configuration.add(DBConstants.BILLING_PU, configurer);
>>   }
>> -----------------------
>> 
>> On Jul 12, 2011, at 4:06 PM, Igor Drobiazko wrote:
>> 
>>> On Tue, Jul 12, 2011 at 9:53 PM, Lenny Primak <lprimak@hope.nyc.ny.us
>>> wrote:
>>> 
>>>> I've been trying to figure out how to add package name to an existing PU
>>>> read from persistence.xml,
>>>> can you share some code on how to do that?  That would work for me just
>>>> fine.
>>>> I am unable to figure that out.
>>>> 
>>> 
>>> Check out this module:
>>> 
>>> 
>> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app1/services/AppModule.java?view=markup
>>> 
>>> The persistence units read from persistence.xml are edited by adding
>> managed
>>> classes.
>>> 
>>> 
>>>> 
>>>> About scanning all packages, in my situation there is production and
>>>> development databases,
>>>> they have exactly the same schema, so in this instance scanning all
>>>> packages is the right thing to do,
>>>> 
>>> 
>>> So, actually you have a single persistence unit which connects to
>> different
>>> databases based on the current environment. Right? In this case you could
>>> override the location of the test persistence descriptor, as here:
>>> 
>>>   @Contribute(SymbolProvider.class)
>>>   @ApplicationDefaults
>>>   public static void provideFactoryDefaults(
>>>           final MappedConfiguration<String, String> configuration)
>>>   {
>>>       configuration.add(JpaSymbols.PERSISTENCE_DESCRIPTOR,
>>> "/single-persistence-unit.xml");
>>>   }
>>> 
>>> 
>>> 
>>>> but I would be very happy with contributePackages() working in case of
>>>> multiple PUs.
>>>> That's documented well and easy to set up.
>>>> Thanks again!
>>>> 
>>>> 
>>>> On Jul 12, 2011, at 3:47 PM, Igor Drobiazko wrote:
>>>> 
>>>>> On Tue, Jul 12, 2011 at 9:24 PM, Lenny Primak <lprimak@hope.nyc.ny.us
>>>>> wrote:
>>>>> 
>>>>>> Thanks again Igor,
>>>>>> Unfortunately, we have other parts of the app using persistence.xml,
>>>>>> so this isn't a great solution.
>>>>>> I don't really see a way to do this cleanly with this method.
>>>>>> 
>>>>> 
>>>>> You can still have a persistence.xml file. A PersistenceUnitConfigurer
>>>> may
>>>>> be contributed to configure a persistence unit from scratch (without
>>>>> persistence.xml) or to modify the information read from
>> persistence.xml.
>>>> So,
>>>>> you just need to
>>>>> 
>>>>>> 
>>>>>> May I suggest the following patch:
>>>>>> EntityManagerSourceImpl.java,
>>>>>> 
>>>>>> ------------- instead of ------------
>>>>>> if(persistenceUnitInfos.size() == 1)
>>>>>> 
>>>>>> 
>>>> 
>> packageNamePersistenceUnitConfigurer.configure(persistenceUnitInfos.get(0));
>>>>>> -------
>>>>>> just call packageNamePersistenceUnitConfigurer.configure() for all the
>>>> PUs.
>>>>>> 
>>>>> 
>>>>> Scanning the classpath for the entities (if multiple units are present)
>>>> and
>>>>> adding them to all the available persistence units doesn't make sense.
>>>> Does
>>>>> it?  Why would you provide several persistence units if they all are
>> have
>>>>> the same set of entities? Wouldn't it cause data inconsistency issues?
>>>>> 
>>>>> 
>>>>> 
>>>>>> I don't see this causing any harm and will fix my problem in an
>> instant.
>>>>>> 
>>>>>> 
>>>>>> On Jul 12, 2011, at 3:08 PM, Igor Drobiazko wrote:
>>>>>> 
>>>>>>> On Tue, Jul 12, 2011 at 9:02 PM, Lenny Primak <
>> lprimak@hope.nyc.ny.us
>>>>>>> wrote:
>>>>>>> 
>>>>>>>> I'm having trouble figuring this out.  Can you help me so I can go
>> on
>>>> a
>>>>>>>> well deserved vacation?
>>>>>>>> 
>>>>>>> 
>>>>>>> I wasn't fast enough since your last mail :) Please checkout the
>>>>>> "XML-less
>>>>>>> JPA configuration" section at the following page.
>>>>>>> 
>>>>>>> http://tapestry.apache.org/integrating-with-jpa.html
>>>>>>> 
>>>>>>> On that page you will find an example of a contribution to the
>>>>>>> EntityManagerSource service. The passed TapestryPersistenceUnitInfo
>>>>>> instance
>>>>>>> can be used to add managed classes.
>>>>>>> 
>>>>>>> 
>>>>>>>> BTW your book is fantastic!
>>>>>>>> 
>>>>>>>> 
>>>>>>> Thank you.
>>>>>>> 
>>>>>>> BTW your feedback on the JPA integration is very much appreciated.
>>>>>> Tapestry
>>>>>>> 5.3 is alpha now. Thanks for using it and providing very valuable
>>>>>> feedback.
>>>>>>> 
>>>>>>> --
>>>>>>> Best regards,
>>>>>>> 
>>>>>>> Igor Drobiazko
>>>>>>> http://tapestry5.de
>>>>>> 
>>>>>> 
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>>> 
>>>>>> 
>>>>> 
>>>>> 
>>>>> --
>>>>> Best regards,
>>>>> 
>>>>> Igor Drobiazko
>>>>> http://tapestry5.de
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>> 
>>>> 
>>> 
>>> 
>>> --
>>> Best regards,
>>> 
>>> Igor Drobiazko
>>> http://tapestry5.de
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
>> 
> 
> 
> -- 
> Best regards,
> 
> Igor Drobiazko
> http://tapestry5.de


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Igor Drobiazko <ig...@gmail.com>.
On Tue, Jul 12, 2011 at 10:28 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:

> Thank you!  That finally worked.
>

Great.

>
> Definitely not trivial to figure out...
>

Well, actually the documentation mentions how to configure persistence units
programmatically.

http://tapestry.apache.org/integrating-with-jpa.html

However, comments on improving the doc are welcome.


> Here is the code if anybody is interested:
>

BTW: The if-check in your code is not needed, as you associate the
configurer with the unit using:

 configuration.add(DBConstants.BILLING_PU, configurer);


> -----------------------------------------
>    @Contribute(EntityManagerSource.class)
>    public static void configurePUs(
>            final MappedConfiguration<String, PersistenceUnitConfigurer>
> configuration, final ClassNameLocator locator)
>    {
>        final PersistenceUnitConfigurer configurer = new
> PersistenceUnitConfigurer()
>        {
>            @Override
>            public void configure(final TapestryPersistenceUnitInfo
> unitInfo)
>            {
>                if
> (unitInfo.getPersistenceUnitName().equals(DBConstants.BILLING_PU))
>                {
>                    for (String className :
> locator.locateClassNames("com.baw.website.entities"))
>                    {
>                        unitInfo.addManagedClassName(className);
>                    }
>                }
>            }
>        };
>        configuration.add(DBConstants.BILLING_PU, configurer);
>    }
> -----------------------
>
> On Jul 12, 2011, at 4:06 PM, Igor Drobiazko wrote:
>
> > On Tue, Jul 12, 2011 at 9:53 PM, Lenny Primak <lprimak@hope.nyc.ny.us
> >wrote:
> >
> >> I've been trying to figure out how to add package name to an existing PU
> >> read from persistence.xml,
> >> can you share some code on how to do that?  That would work for me just
> >> fine.
> >> I am unable to figure that out.
> >>
> >
> > Check out this module:
> >
> >
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app1/services/AppModule.java?view=markup
> >
> > The persistence units read from persistence.xml are edited by adding
> managed
> > classes.
> >
> >
> >>
> >> About scanning all packages, in my situation there is production and
> >> development databases,
> >> they have exactly the same schema, so in this instance scanning all
> >> packages is the right thing to do,
> >>
> >
> > So, actually you have a single persistence unit which connects to
> different
> > databases based on the current environment. Right? In this case you could
> > override the location of the test persistence descriptor, as here:
> >
> >    @Contribute(SymbolProvider.class)
> >    @ApplicationDefaults
> >    public static void provideFactoryDefaults(
> >            final MappedConfiguration<String, String> configuration)
> >    {
> >        configuration.add(JpaSymbols.PERSISTENCE_DESCRIPTOR,
> > "/single-persistence-unit.xml");
> >    }
> >
> >
> >
> >> but I would be very happy with contributePackages() working in case of
> >> multiple PUs.
> >> That's documented well and easy to set up.
> >> Thanks again!
> >>
> >>
> >> On Jul 12, 2011, at 3:47 PM, Igor Drobiazko wrote:
> >>
> >>> On Tue, Jul 12, 2011 at 9:24 PM, Lenny Primak <lprimak@hope.nyc.ny.us
> >>> wrote:
> >>>
> >>>> Thanks again Igor,
> >>>> Unfortunately, we have other parts of the app using persistence.xml,
> >>>> so this isn't a great solution.
> >>>> I don't really see a way to do this cleanly with this method.
> >>>>
> >>>
> >>> You can still have a persistence.xml file. A PersistenceUnitConfigurer
> >> may
> >>> be contributed to configure a persistence unit from scratch (without
> >>> persistence.xml) or to modify the information read from
> persistence.xml.
> >> So,
> >>> you just need to
> >>>
> >>>>
> >>>> May I suggest the following patch:
> >>>> EntityManagerSourceImpl.java,
> >>>>
> >>>> ------------- instead of ------------
> >>>> if(persistenceUnitInfos.size() == 1)
> >>>>
> >>>>
> >>
> packageNamePersistenceUnitConfigurer.configure(persistenceUnitInfos.get(0));
> >>>> -------
> >>>> just call packageNamePersistenceUnitConfigurer.configure() for all the
> >> PUs.
> >>>>
> >>>
> >>> Scanning the classpath for the entities (if multiple units are present)
> >> and
> >>> adding them to all the available persistence units doesn't make sense.
> >> Does
> >>> it?  Why would you provide several persistence units if they all are
> have
> >>> the same set of entities? Wouldn't it cause data inconsistency issues?
> >>>
> >>>
> >>>
> >>>> I don't see this causing any harm and will fix my problem in an
> instant.
> >>>>
> >>>>
> >>>> On Jul 12, 2011, at 3:08 PM, Igor Drobiazko wrote:
> >>>>
> >>>>> On Tue, Jul 12, 2011 at 9:02 PM, Lenny Primak <
> lprimak@hope.nyc.ny.us
> >>>>> wrote:
> >>>>>
> >>>>>> I'm having trouble figuring this out.  Can you help me so I can go
> on
> >> a
> >>>>>> well deserved vacation?
> >>>>>>
> >>>>>
> >>>>> I wasn't fast enough since your last mail :) Please checkout the
> >>>> "XML-less
> >>>>> JPA configuration" section at the following page.
> >>>>>
> >>>>> http://tapestry.apache.org/integrating-with-jpa.html
> >>>>>
> >>>>> On that page you will find an example of a contribution to the
> >>>>> EntityManagerSource service. The passed TapestryPersistenceUnitInfo
> >>>> instance
> >>>>> can be used to add managed classes.
> >>>>>
> >>>>>
> >>>>>> BTW your book is fantastic!
> >>>>>>
> >>>>>>
> >>>>> Thank you.
> >>>>>
> >>>>> BTW your feedback on the JPA integration is very much appreciated.
> >>>> Tapestry
> >>>>> 5.3 is alpha now. Thanks for using it and providing very valuable
> >>>> feedback.
> >>>>>
> >>>>> --
> >>>>> Best regards,
> >>>>>
> >>>>> Igor Drobiazko
> >>>>> http://tapestry5.de
> >>>>
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >>>> For additional commands, e-mail: users-help@tapestry.apache.org
> >>>>
> >>>>
> >>>
> >>>
> >>> --
> >>> Best regards,
> >>>
> >>> Igor Drobiazko
> >>> http://tapestry5.de
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
> >
> >
> > --
> > Best regards,
> >
> > Igor Drobiazko
> > http://tapestry5.de
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de

Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
Thank you!  That finally worked.

Definitely not trivial to figure out...

Here is the code if anybody is interested:
-----------------------------------------
    @Contribute(EntityManagerSource.class)
    public static void configurePUs(
            final MappedConfiguration<String, PersistenceUnitConfigurer> configuration, final ClassNameLocator locator)
    {
        final PersistenceUnitConfigurer configurer = new PersistenceUnitConfigurer()
        {
            @Override
            public void configure(final TapestryPersistenceUnitInfo unitInfo)
            {
                if (unitInfo.getPersistenceUnitName().equals(DBConstants.BILLING_PU))
                {
                    for (String className : locator.locateClassNames("com.baw.website.entities"))
                    {
                        unitInfo.addManagedClassName(className);
                    }
                }
            }
        };
        configuration.add(DBConstants.BILLING_PU, configurer);
    }   
-----------------------

On Jul 12, 2011, at 4:06 PM, Igor Drobiazko wrote:

> On Tue, Jul 12, 2011 at 9:53 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:
> 
>> I've been trying to figure out how to add package name to an existing PU
>> read from persistence.xml,
>> can you share some code on how to do that?  That would work for me just
>> fine.
>> I am unable to figure that out.
>> 
> 
> Check out this module:
> 
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app1/services/AppModule.java?view=markup
> 
> The persistence units read from persistence.xml are edited by adding managed
> classes.
> 
> 
>> 
>> About scanning all packages, in my situation there is production and
>> development databases,
>> they have exactly the same schema, so in this instance scanning all
>> packages is the right thing to do,
>> 
> 
> So, actually you have a single persistence unit which connects to different
> databases based on the current environment. Right? In this case you could
> override the location of the test persistence descriptor, as here:
> 
>    @Contribute(SymbolProvider.class)
>    @ApplicationDefaults
>    public static void provideFactoryDefaults(
>            final MappedConfiguration<String, String> configuration)
>    {
>        configuration.add(JpaSymbols.PERSISTENCE_DESCRIPTOR,
> "/single-persistence-unit.xml");
>    }
> 
> 
> 
>> but I would be very happy with contributePackages() working in case of
>> multiple PUs.
>> That's documented well and easy to set up.
>> Thanks again!
>> 
>> 
>> On Jul 12, 2011, at 3:47 PM, Igor Drobiazko wrote:
>> 
>>> On Tue, Jul 12, 2011 at 9:24 PM, Lenny Primak <lprimak@hope.nyc.ny.us
>>> wrote:
>>> 
>>>> Thanks again Igor,
>>>> Unfortunately, we have other parts of the app using persistence.xml,
>>>> so this isn't a great solution.
>>>> I don't really see a way to do this cleanly with this method.
>>>> 
>>> 
>>> You can still have a persistence.xml file. A PersistenceUnitConfigurer
>> may
>>> be contributed to configure a persistence unit from scratch (without
>>> persistence.xml) or to modify the information read from persistence.xml.
>> So,
>>> you just need to
>>> 
>>>> 
>>>> May I suggest the following patch:
>>>> EntityManagerSourceImpl.java,
>>>> 
>>>> ------------- instead of ------------
>>>> if(persistenceUnitInfos.size() == 1)
>>>> 
>>>> 
>> packageNamePersistenceUnitConfigurer.configure(persistenceUnitInfos.get(0));
>>>> -------
>>>> just call packageNamePersistenceUnitConfigurer.configure() for all the
>> PUs.
>>>> 
>>> 
>>> Scanning the classpath for the entities (if multiple units are present)
>> and
>>> adding them to all the available persistence units doesn't make sense.
>> Does
>>> it?  Why would you provide several persistence units if they all are have
>>> the same set of entities? Wouldn't it cause data inconsistency issues?
>>> 
>>> 
>>> 
>>>> I don't see this causing any harm and will fix my problem in an instant.
>>>> 
>>>> 
>>>> On Jul 12, 2011, at 3:08 PM, Igor Drobiazko wrote:
>>>> 
>>>>> On Tue, Jul 12, 2011 at 9:02 PM, Lenny Primak <lprimak@hope.nyc.ny.us
>>>>> wrote:
>>>>> 
>>>>>> I'm having trouble figuring this out.  Can you help me so I can go on
>> a
>>>>>> well deserved vacation?
>>>>>> 
>>>>> 
>>>>> I wasn't fast enough since your last mail :) Please checkout the
>>>> "XML-less
>>>>> JPA configuration" section at the following page.
>>>>> 
>>>>> http://tapestry.apache.org/integrating-with-jpa.html
>>>>> 
>>>>> On that page you will find an example of a contribution to the
>>>>> EntityManagerSource service. The passed TapestryPersistenceUnitInfo
>>>> instance
>>>>> can be used to add managed classes.
>>>>> 
>>>>> 
>>>>>> BTW your book is fantastic!
>>>>>> 
>>>>>> 
>>>>> Thank you.
>>>>> 
>>>>> BTW your feedback on the JPA integration is very much appreciated.
>>>> Tapestry
>>>>> 5.3 is alpha now. Thanks for using it and providing very valuable
>>>> feedback.
>>>>> 
>>>>> --
>>>>> Best regards,
>>>>> 
>>>>> Igor Drobiazko
>>>>> http://tapestry5.de
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>> 
>>>> 
>>> 
>>> 
>>> --
>>> Best regards,
>>> 
>>> Igor Drobiazko
>>> http://tapestry5.de
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
>> 
> 
> 
> -- 
> Best regards,
> 
> Igor Drobiazko
> http://tapestry5.de


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Igor Drobiazko <ig...@gmail.com>.
On Tue, Jul 12, 2011 at 9:53 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:

> I've been trying to figure out how to add package name to an existing PU
> read from persistence.xml,
> can you share some code on how to do that?  That would work for me just
> fine.
> I am unable to figure that out.
>

Check out this module:

http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-jpa/src/test/java/org/example/app1/services/AppModule.java?view=markup

The persistence units read from persistence.xml are edited by adding managed
classes.


>
> About scanning all packages, in my situation there is production and
> development databases,
> they have exactly the same schema, so in this instance scanning all
> packages is the right thing to do,
>

So, actually you have a single persistence unit which connects to different
databases based on the current environment. Right? In this case you could
override the location of the test persistence descriptor, as here:

    @Contribute(SymbolProvider.class)
    @ApplicationDefaults
    public static void provideFactoryDefaults(
            final MappedConfiguration<String, String> configuration)
    {
        configuration.add(JpaSymbols.PERSISTENCE_DESCRIPTOR,
"/single-persistence-unit.xml");
    }



> but I would be very happy with contributePackages() working in case of
> multiple PUs.
> That's documented well and easy to set up.
> Thanks again!
>
>
> On Jul 12, 2011, at 3:47 PM, Igor Drobiazko wrote:
>
> > On Tue, Jul 12, 2011 at 9:24 PM, Lenny Primak <lprimak@hope.nyc.ny.us
> >wrote:
> >
> >> Thanks again Igor,
> >> Unfortunately, we have other parts of the app using persistence.xml,
> >> so this isn't a great solution.
> >> I don't really see a way to do this cleanly with this method.
> >>
> >
> > You can still have a persistence.xml file. A PersistenceUnitConfigurer
> may
> > be contributed to configure a persistence unit from scratch (without
> > persistence.xml) or to modify the information read from persistence.xml.
> So,
> > you just need to
> >
> >>
> >> May I suggest the following patch:
> >> EntityManagerSourceImpl.java,
> >>
> >> ------------- instead of ------------
> >> if(persistenceUnitInfos.size() == 1)
> >>
> >>
> packageNamePersistenceUnitConfigurer.configure(persistenceUnitInfos.get(0));
> >> -------
> >> just call packageNamePersistenceUnitConfigurer.configure() for all the
> PUs.
> >>
> >
> > Scanning the classpath for the entities (if multiple units are present)
> and
> > adding them to all the available persistence units doesn't make sense.
> Does
> > it?  Why would you provide several persistence units if they all are have
> > the same set of entities? Wouldn't it cause data inconsistency issues?
> >
> >
> >
> >> I don't see this causing any harm and will fix my problem in an instant.
> >>
> >>
> >> On Jul 12, 2011, at 3:08 PM, Igor Drobiazko wrote:
> >>
> >>> On Tue, Jul 12, 2011 at 9:02 PM, Lenny Primak <lprimak@hope.nyc.ny.us
> >>> wrote:
> >>>
> >>>> I'm having trouble figuring this out.  Can you help me so I can go on
> a
> >>>> well deserved vacation?
> >>>>
> >>>
> >>> I wasn't fast enough since your last mail :) Please checkout the
> >> "XML-less
> >>> JPA configuration" section at the following page.
> >>>
> >>> http://tapestry.apache.org/integrating-with-jpa.html
> >>>
> >>> On that page you will find an example of a contribution to the
> >>> EntityManagerSource service. The passed TapestryPersistenceUnitInfo
> >> instance
> >>> can be used to add managed classes.
> >>>
> >>>
> >>>> BTW your book is fantastic!
> >>>>
> >>>>
> >>> Thank you.
> >>>
> >>> BTW your feedback on the JPA integration is very much appreciated.
> >> Tapestry
> >>> 5.3 is alpha now. Thanks for using it and providing very valuable
> >> feedback.
> >>>
> >>> --
> >>> Best regards,
> >>>
> >>> Igor Drobiazko
> >>> http://tapestry5.de
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
> >
> >
> > --
> > Best regards,
> >
> > Igor Drobiazko
> > http://tapestry5.de
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de

Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
I've been trying to figure out how to add package name to an existing PU read from persistence.xml,
can you share some code on how to do that?  That would work for me just fine.
I am unable to figure that out.

About scanning all packages, in my situation there is production and development databases,
they have exactly the same schema, so in this instance scanning all packages is the right thing to do,
but I would be very happy with contributePackages() working in case of multiple PUs.
That's documented well and easy to set up.
Thanks again!


On Jul 12, 2011, at 3:47 PM, Igor Drobiazko wrote:

> On Tue, Jul 12, 2011 at 9:24 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:
> 
>> Thanks again Igor,
>> Unfortunately, we have other parts of the app using persistence.xml,
>> so this isn't a great solution.
>> I don't really see a way to do this cleanly with this method.
>> 
> 
> You can still have a persistence.xml file. A PersistenceUnitConfigurer may
> be contributed to configure a persistence unit from scratch (without
> persistence.xml) or to modify the information read from persistence.xml. So,
> you just need to
> 
>> 
>> May I suggest the following patch:
>> EntityManagerSourceImpl.java,
>> 
>> ------------- instead of ------------
>> if(persistenceUnitInfos.size() == 1)
>> 
>> packageNamePersistenceUnitConfigurer.configure(persistenceUnitInfos.get(0));
>> -------
>> just call packageNamePersistenceUnitConfigurer.configure() for all the PUs.
>> 
> 
> Scanning the classpath for the entities (if multiple units are present) and
> adding them to all the available persistence units doesn't make sense. Does
> it?  Why would you provide several persistence units if they all are have
> the same set of entities? Wouldn't it cause data inconsistency issues?
> 
> 
> 
>> I don't see this causing any harm and will fix my problem in an instant.
>> 
>> 
>> On Jul 12, 2011, at 3:08 PM, Igor Drobiazko wrote:
>> 
>>> On Tue, Jul 12, 2011 at 9:02 PM, Lenny Primak <lprimak@hope.nyc.ny.us
>>> wrote:
>>> 
>>>> I'm having trouble figuring this out.  Can you help me so I can go on a
>>>> well deserved vacation?
>>>> 
>>> 
>>> I wasn't fast enough since your last mail :) Please checkout the
>> "XML-less
>>> JPA configuration" section at the following page.
>>> 
>>> http://tapestry.apache.org/integrating-with-jpa.html
>>> 
>>> On that page you will find an example of a contribution to the
>>> EntityManagerSource service. The passed TapestryPersistenceUnitInfo
>> instance
>>> can be used to add managed classes.
>>> 
>>> 
>>>> BTW your book is fantastic!
>>>> 
>>>> 
>>> Thank you.
>>> 
>>> BTW your feedback on the JPA integration is very much appreciated.
>> Tapestry
>>> 5.3 is alpha now. Thanks for using it and providing very valuable
>> feedback.
>>> 
>>> --
>>> Best regards,
>>> 
>>> Igor Drobiazko
>>> http://tapestry5.de
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
>> 
> 
> 
> -- 
> Best regards,
> 
> Igor Drobiazko
> http://tapestry5.de


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Igor Drobiazko <ig...@gmail.com>.
On Tue, Jul 12, 2011 at 9:24 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:

> Thanks again Igor,
> Unfortunately, we have other parts of the app using persistence.xml,
> so this isn't a great solution.
> I don't really see a way to do this cleanly with this method.
>

You can still have a persistence.xml file. A PersistenceUnitConfigurer may
be contributed to configure a persistence unit from scratch (without
persistence.xml) or to modify the information read from persistence.xml. So,
you just need to

>
> May I suggest the following patch:
> EntityManagerSourceImpl.java,
>
> ------------- instead of ------------
> if(persistenceUnitInfos.size() == 1)
>
>  packageNamePersistenceUnitConfigurer.configure(persistenceUnitInfos.get(0));
> -------
> just call packageNamePersistenceUnitConfigurer.configure() for all the PUs.
>

Scanning the classpath for the entities (if multiple units are present) and
adding them to all the available persistence units doesn't make sense. Does
it?  Why would you provide several persistence units if they all are have
the same set of entities? Wouldn't it cause data inconsistency issues?



> I don't see this causing any harm and will fix my problem in an instant.
>
>
> On Jul 12, 2011, at 3:08 PM, Igor Drobiazko wrote:
>
> > On Tue, Jul 12, 2011 at 9:02 PM, Lenny Primak <lprimak@hope.nyc.ny.us
> >wrote:
> >
> >> I'm having trouble figuring this out.  Can you help me so I can go on a
> >> well deserved vacation?
> >>
> >
> > I wasn't fast enough since your last mail :) Please checkout the
> "XML-less
> > JPA configuration" section at the following page.
> >
> > http://tapestry.apache.org/integrating-with-jpa.html
> >
> > On that page you will find an example of a contribution to the
> > EntityManagerSource service. The passed TapestryPersistenceUnitInfo
> instance
> > can be used to add managed classes.
> >
> >
> >> BTW your book is fantastic!
> >>
> >>
> > Thank you.
> >
> > BTW your feedback on the JPA integration is very much appreciated.
> Tapestry
> > 5.3 is alpha now. Thanks for using it and providing very valuable
> feedback.
> >
> > --
> > Best regards,
> >
> > Igor Drobiazko
> > http://tapestry5.de
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de

Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
Thanks again Igor,
Unfortunately, we have other parts of the app using persistence.xml,
so this isn't a great solution.
I don't really see a way to do this cleanly with this method.

May I suggest the following patch:
EntityManagerSourceImpl.java,

------------- instead of ------------
if(persistenceUnitInfos.size() == 1)
            packageNamePersistenceUnitConfigurer.configure(persistenceUnitInfos.get(0));
-------
just call packageNamePersistenceUnitConfigurer.configure() for all the PUs.

I don't see this causing any harm and will fix my problem in an instant.


On Jul 12, 2011, at 3:08 PM, Igor Drobiazko wrote:

> On Tue, Jul 12, 2011 at 9:02 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:
> 
>> I'm having trouble figuring this out.  Can you help me so I can go on a
>> well deserved vacation?
>> 
> 
> I wasn't fast enough since your last mail :) Please checkout the "XML-less
> JPA configuration" section at the following page.
> 
> http://tapestry.apache.org/integrating-with-jpa.html
> 
> On that page you will find an example of a contribution to the
> EntityManagerSource service. The passed TapestryPersistenceUnitInfo instance
> can be used to add managed classes.
> 
> 
>> BTW your book is fantastic!
>> 
>> 
> Thank you.
> 
> BTW your feedback on the JPA integration is very much appreciated. Tapestry
> 5.3 is alpha now. Thanks for using it and providing very valuable feedback.
> 
> -- 
> Best regards,
> 
> Igor Drobiazko
> http://tapestry5.de


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Igor Drobiazko <ig...@gmail.com>.
On Tue, Jul 12, 2011 at 9:02 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:

> I'm having trouble figuring this out.  Can you help me so I can go on a
> well deserved vacation?
>

I wasn't fast enough since your last mail :) Please checkout the "XML-less
JPA configuration" section at the following page.

http://tapestry.apache.org/integrating-with-jpa.html

On that page you will find an example of a contribution to the
EntityManagerSource service. The passed TapestryPersistenceUnitInfo instance
 can be used to add managed classes.


> BTW your book is fantastic!
>
>
Thank you.

BTW your feedback on the JPA integration is very much appreciated. Tapestry
5.3 is alpha now. Thanks for using it and providing very valuable feedback.

-- 
Best regards,

Igor Drobiazko
http://tapestry5.de

Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
I'm having trouble figuring this out.  Can you help me so I can go on a well deserved vacation?
BTW your book is fantastic!

On Jul 12, 2011, at 2:09 PM, Igor Drobiazko wrote:

> Hi Lenny,
> 
> the JpaEntityPackageManager service is invoked if only a single persistence
> unit is defined. The reasons are:
> 
> 1) 99% of the apps are using a single persistence unit. In this
> case, auto-configuring entities from the entities su-package is very
> useful.
> 2) if multiple persistence units are defined, Tapestry doesn't know where to
> add the entities.
> 
> The documentations mentions that. Maybe it should be emphasized a little bit
> more.
> 
> So, you need to contribute a PersistenceUnitConfigurer to the
> EntityManagerSource service's configuration.
> 
> 
> On Tue, Jul 12, 2011 at 7:00 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:
> 
>> I use persistense.xml.
>> 
>> I don't think  @Contribute(JpaEntityPackageManager.class)    public static
>> void providePackages(Configuration<String> configuration)
>> is getting called, hence continuing of my frustrations.
>> Still need help with getting that resolved.
>> 
>> Thanks!
>> 
>> Here is my persistense.xml:
>> ----------------
>> <?xml version="1.0" encoding="UTF-8"?>
>> <persistence version="2.0" 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_2_0.xsd">
>> <persistence-unit name="BillingPUTest" transaction-type="JTA">
>>   <jta-data-source>jdbc/BillingTest</jta-data-source>
>>   <exclude-unlisted-classes>false</exclude-unlisted-classes>
>>   <properties/>
>> </persistence-unit>
>> 
>> <persistence-unit name="BillingPUProd" transaction-type="JTA">
>>   <jta-data-source>jdbc/BillingProd</jta-data-source>
>>   <exclude-unlisted-classes>false</exclude-unlisted-classes>
>>   <properties/>
>> </persistence-unit>
>> </persistence>
>> 
>> 
>> On Jul 12, 2011, at 11:15 AM, Igor Drobiazko wrote:
>> 
>>> Looks like named query is not know in the BillingPUTest persistence unit.
>>> How did you define it?
>>> 
>>> On Tue, Jul 12, 2011 at 2:19 PM, Lenny Primak <lprimak@hope.nyc.ny.us
>>> wrote:
>>> 
>>>> I am using Tapestry 5.3 and the JPA module 5.3
>>>> 
>>>> In my Page class:
>>>> 
>>>> @PersistenceContext(unitName = "BillingPUTest") private EntityManager
>> em;
>>>> 
>>>> @SuppressWarnings("unused")
>>>>  @PageAttached
>>>>  private void populate()
>>>>  {
>>>>  //   userList = facade.findAll();
>>>>      // either variant will work the same
>>>>     userList = em.createNamedQuery("Webusers.findAll",
>>>> Webusers.class).getResultList();
>>>>  }
>>>> 
>>>> When I have only one persistent unit in persistence.xml, everything
>> works,
>>>> but once I add another unit (i.e. production database) I get the
>> following
>>>> exception:
>>>> 
>>>> ava.lang.RuntimeException
>>>> Unable to attach page TapPage: NamedQuery of name: Webusers.findAll not
>>>> found.
>>>> java.lang.IllegalArgumentException
>>>> NamedQuery of name: Webusers.findAll not found.
>>>> Hide uninteresting stack framesStack trace
>>>> 
>>>> 
>> org.eclipse.persistence.internal.jpa.EJBQueryImpl.getDatabaseQueryInternal(EJBQueryImpl.java:576)
>>>> 
>>>> 
>> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1004)
>>>> 
>>>> 
>> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1024)
>>>> com.baw.website.pages.TapPage.populate(TapPage.java:25)
>>>> 
>> com.baw.website.pages.TapPage.populate$access122fbc563a57e270(TapPage.java)
>>>> com.baw.website.pages.TapPage$Shim_122fbc563a57e26f.invoke(Unknown
>> Source)
>>>> 
>>>> 
>> org.apache.tapestry5.internal.plastic.MethodHandleImpl.invoke(MethodHandleImpl.java:48)
>>>> It also works every time from a session bean, just not from an EM
>> injected
>>>> into the tapestry page.
>>>> 
>>>> Please help!
>>>> 
>>>> 
>>> 
>>> 
>>> --
>>> Best regards,
>>> 
>>> Igor Drobiazko
>>> http://tapestry5.de
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
>> 
> 
> 
> -- 
> Best regards,
> 
> Igor Drobiazko
> http://tapestry5.de


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
Igor, do you mind sending me quick sample on how to do this?
Really appreciate it.  This is a bit confusing to me.

On Jul 12, 2011, at 2:09 PM, Igor Drobiazko wrote:

> Hi Lenny,
> 
> 
> So, you need to contribute a PersistenceUnitConfigurer to the
> EntityManagerSource service's configuration.
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Igor Drobiazko <ig...@gmail.com>.
On Tue, Jul 12, 2011 at 8:20 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:
>
>
> If I may offer a suggestion...
> In case of multiple persistence units, perhaps it would be better to scan
> the whole app for entities,
> rather than scan nothing.  This would seem much more appropriate default
> behavior,
> as it is not at all clear and simple how to get this to work in this case.
>

I'll have a look whether that makes sense.


>
> Tynamo JPA worked right out of the box, but I spent about 12 hours going
> through configuration witih the JPA module.
>

Well, it's not quite correct. Tynamo didn't support multiple persistence
units. If you would use Tapestry JPA with a single persistence unit, it
would work out of the box too ;)



-- 
Best regards,

Igor Drobiazko
http://tapestry5.de

Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
Thanks again, Igor, I will try this out.

If I may offer a suggestion...
In case of multiple persistence units, perhaps it would be better to scan the whole app for entities,
rather than scan nothing.  This would seem much more appropriate default behavior,
as it is not at all clear and simple how to get this to work in this case.

Tynamo JPA worked right out of the box, but I spent about 12 hours going
through configuration witih the JPA module.

Just a suggestion, and thanks again.

On Jul 12, 2011, at 2:09 PM, Igor Drobiazko wrote:

> Hi Lenny,
> 
> the JpaEntityPackageManager service is invoked if only a single persistence
> unit is defined. The reasons are:
> 
> 1) 99% of the apps are using a single persistence unit. In this
> case, auto-configuring entities from the entities su-package is very
> useful.
> 2) if multiple persistence units are defined, Tapestry doesn't know where to
> add the entities.
> 
> The documentations mentions that. Maybe it should be emphasized a little bit
> more.
> 
> So, you need to contribute a PersistenceUnitConfigurer to the
> EntityManagerSource service's configuration.
> 
> 
> On Tue, Jul 12, 2011 at 7:00 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:
> 
>> I use persistense.xml.
>> 
>> I don't think  @Contribute(JpaEntityPackageManager.class)    public static
>> void providePackages(Configuration<String> configuration)
>> is getting called, hence continuing of my frustrations.
>> Still need help with getting that resolved.
>> 
>> Thanks!
>> 
>> Here is my persistense.xml:
>> ----------------
>> <?xml version="1.0" encoding="UTF-8"?>
>> <persistence version="2.0" 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_2_0.xsd">
>> <persistence-unit name="BillingPUTest" transaction-type="JTA">
>>   <jta-data-source>jdbc/BillingTest</jta-data-source>
>>   <exclude-unlisted-classes>false</exclude-unlisted-classes>
>>   <properties/>
>> </persistence-unit>
>> 
>> <persistence-unit name="BillingPUProd" transaction-type="JTA">
>>   <jta-data-source>jdbc/BillingProd</jta-data-source>
>>   <exclude-unlisted-classes>false</exclude-unlisted-classes>
>>   <properties/>
>> </persistence-unit>
>> </persistence>
>> 
>> 
>> On Jul 12, 2011, at 11:15 AM, Igor Drobiazko wrote:
>> 
>>> Looks like named query is not know in the BillingPUTest persistence unit.
>>> How did you define it?
>>> 
>>> On Tue, Jul 12, 2011 at 2:19 PM, Lenny Primak <lprimak@hope.nyc.ny.us
>>> wrote:
>>> 
>>>> I am using Tapestry 5.3 and the JPA module 5.3
>>>> 
>>>> In my Page class:
>>>> 
>>>> @PersistenceContext(unitName = "BillingPUTest") private EntityManager
>> em;
>>>> 
>>>> @SuppressWarnings("unused")
>>>>  @PageAttached
>>>>  private void populate()
>>>>  {
>>>>  //   userList = facade.findAll();
>>>>      // either variant will work the same
>>>>     userList = em.createNamedQuery("Webusers.findAll",
>>>> Webusers.class).getResultList();
>>>>  }
>>>> 
>>>> When I have only one persistent unit in persistence.xml, everything
>> works,
>>>> but once I add another unit (i.e. production database) I get the
>> following
>>>> exception:
>>>> 
>>>> ava.lang.RuntimeException
>>>> Unable to attach page TapPage: NamedQuery of name: Webusers.findAll not
>>>> found.
>>>> java.lang.IllegalArgumentException
>>>> NamedQuery of name: Webusers.findAll not found.
>>>> Hide uninteresting stack framesStack trace
>>>> 
>>>> 
>> org.eclipse.persistence.internal.jpa.EJBQueryImpl.getDatabaseQueryInternal(EJBQueryImpl.java:576)
>>>> 
>>>> 
>> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1004)
>>>> 
>>>> 
>> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1024)
>>>> com.baw.website.pages.TapPage.populate(TapPage.java:25)
>>>> 
>> com.baw.website.pages.TapPage.populate$access122fbc563a57e270(TapPage.java)
>>>> com.baw.website.pages.TapPage$Shim_122fbc563a57e26f.invoke(Unknown
>> Source)
>>>> 
>>>> 
>> org.apache.tapestry5.internal.plastic.MethodHandleImpl.invoke(MethodHandleImpl.java:48)
>>>> It also works every time from a session bean, just not from an EM
>> injected
>>>> into the tapestry page.
>>>> 
>>>> Please help!
>>>> 
>>>> 
>>> 
>>> 
>>> --
>>> Best regards,
>>> 
>>> Igor Drobiazko
>>> http://tapestry5.de
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
>> 
> 
> 
> -- 
> Best regards,
> 
> Igor Drobiazko
> http://tapestry5.de


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Igor Drobiazko <ig...@gmail.com>.
Hi Lenny,

the JpaEntityPackageManager service is invoked if only a single persistence
unit is defined. The reasons are:

1) 99% of the apps are using a single persistence unit. In this
case, auto-configuring entities from the entities su-package is very
useful.
2) if multiple persistence units are defined, Tapestry doesn't know where to
add the entities.

The documentations mentions that. Maybe it should be emphasized a little bit
more.

So, you need to contribute a PersistenceUnitConfigurer to the
EntityManagerSource service's configuration.


On Tue, Jul 12, 2011 at 7:00 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:

> I use persistense.xml.
>
> I don't think  @Contribute(JpaEntityPackageManager.class)    public static
> void providePackages(Configuration<String> configuration)
> is getting called, hence continuing of my frustrations.
> Still need help with getting that resolved.
>
> Thanks!
>
> Here is my persistense.xml:
> ----------------
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence version="2.0" 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_2_0.xsd">
>  <persistence-unit name="BillingPUTest" transaction-type="JTA">
>    <jta-data-source>jdbc/BillingTest</jta-data-source>
>    <exclude-unlisted-classes>false</exclude-unlisted-classes>
>    <properties/>
>  </persistence-unit>
>
>  <persistence-unit name="BillingPUProd" transaction-type="JTA">
>    <jta-data-source>jdbc/BillingProd</jta-data-source>
>    <exclude-unlisted-classes>false</exclude-unlisted-classes>
>    <properties/>
>  </persistence-unit>
> </persistence>
>
>
> On Jul 12, 2011, at 11:15 AM, Igor Drobiazko wrote:
>
> > Looks like named query is not know in the BillingPUTest persistence unit.
> > How did you define it?
> >
> > On Tue, Jul 12, 2011 at 2:19 PM, Lenny Primak <lprimak@hope.nyc.ny.us
> >wrote:
> >
> >> I am using Tapestry 5.3 and the JPA module 5.3
> >>
> >> In my Page class:
> >>
> >> @PersistenceContext(unitName = "BillingPUTest") private EntityManager
> em;
> >>
> >> @SuppressWarnings("unused")
> >>   @PageAttached
> >>   private void populate()
> >>   {
> >>   //   userList = facade.findAll();
> >>       // either variant will work the same
> >>      userList = em.createNamedQuery("Webusers.findAll",
> >> Webusers.class).getResultList();
> >>   }
> >>
> >> When I have only one persistent unit in persistence.xml, everything
> works,
> >> but once I add another unit (i.e. production database) I get the
> following
> >> exception:
> >>
> >> ava.lang.RuntimeException
> >> Unable to attach page TapPage: NamedQuery of name: Webusers.findAll not
> >> found.
> >> java.lang.IllegalArgumentException
> >> NamedQuery of name: Webusers.findAll not found.
> >> Hide uninteresting stack framesStack trace
> >>
> >>
> org.eclipse.persistence.internal.jpa.EJBQueryImpl.getDatabaseQueryInternal(EJBQueryImpl.java:576)
> >>
> >>
> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1004)
> >>
> >>
> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1024)
> >> com.baw.website.pages.TapPage.populate(TapPage.java:25)
> >>
> com.baw.website.pages.TapPage.populate$access122fbc563a57e270(TapPage.java)
> >> com.baw.website.pages.TapPage$Shim_122fbc563a57e26f.invoke(Unknown
> Source)
> >>
> >>
> org.apache.tapestry5.internal.plastic.MethodHandleImpl.invoke(MethodHandleImpl.java:48)
> >> It also works every time from a session bean, just not from an EM
> injected
> >> into the tapestry page.
> >>
> >> Please help!
> >>
> >>
> >
> >
> > --
> > Best regards,
> >
> > Igor Drobiazko
> > http://tapestry5.de
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de

Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
Ok, I've debugged this a bit further.  providePagkages() gets called ONLY if there is only one persistence unit in persistence.xml.
On the other hand, in the all-important case of multiple persistence units, providePackages() does not get called.
Any ideas?
Thanks!

On Jul 12, 2011, at 1:00 PM, Lenny Primak wrote:

> I use persistense.xml.
> 
> I don't think  @Contribute(JpaEntityPackageManager.class)    public static void providePackages(Configuration<String> configuration)
> is getting called, hence continuing of my frustrations.
> Still need help with getting that resolved.
> 
> Thanks!
> 
> Here is my persistense.xml:
> ----------------
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence version="2.0" 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_2_0.xsd">
>  <persistence-unit name="BillingPUTest" transaction-type="JTA">
>    <jta-data-source>jdbc/BillingTest</jta-data-source>
>    <exclude-unlisted-classes>false</exclude-unlisted-classes>
>    <properties/>
>  </persistence-unit>
> 
>  <persistence-unit name="BillingPUProd" transaction-type="JTA">
>    <jta-data-source>jdbc/BillingProd</jta-data-source>
>    <exclude-unlisted-classes>false</exclude-unlisted-classes>
>    <properties/>
>  </persistence-unit>
> </persistence>
> 
> 
> On Jul 12, 2011, at 11:15 AM, Igor Drobiazko wrote:
> 
>> Looks like named query is not know in the BillingPUTest persistence unit.
>> How did you define it?
>> 
>> On Tue, Jul 12, 2011 at 2:19 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:
>> 
>>> I am using Tapestry 5.3 and the JPA module 5.3
>>> 
>>> In my Page class:
>>> 
>>> @PersistenceContext(unitName = "BillingPUTest") private EntityManager em;
>>> 
>>> @SuppressWarnings("unused")
>>>  @PageAttached
>>>  private void populate()
>>>  {
>>>  //   userList = facade.findAll();
>>>      // either variant will work the same
>>>     userList = em.createNamedQuery("Webusers.findAll",
>>> Webusers.class).getResultList();
>>>  }
>>> 
>>> When I have only one persistent unit in persistence.xml, everything works,
>>> but once I add another unit (i.e. production database) I get the following
>>> exception:
>>> 
>>> ava.lang.RuntimeException
>>> Unable to attach page TapPage: NamedQuery of name: Webusers.findAll not
>>> found.
>>> java.lang.IllegalArgumentException
>>> NamedQuery of name: Webusers.findAll not found.
>>> Hide uninteresting stack framesStack trace
>>> 
>>> org.eclipse.persistence.internal.jpa.EJBQueryImpl.getDatabaseQueryInternal(EJBQueryImpl.java:576)
>>> 
>>> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1004)
>>> 
>>> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1024)
>>> com.baw.website.pages.TapPage.populate(TapPage.java:25)
>>> com.baw.website.pages.TapPage.populate$access122fbc563a57e270(TapPage.java)
>>> com.baw.website.pages.TapPage$Shim_122fbc563a57e26f.invoke(Unknown Source)
>>> 
>>> org.apache.tapestry5.internal.plastic.MethodHandleImpl.invoke(MethodHandleImpl.java:48)
>>> It also works every time from a session bean, just not from an EM injected
>>> into the tapestry page.
>>> 
>>> Please help!
>>> 
>>> 
>> 
>> 
>> -- 
>> Best regards,
>> 
>> Igor Drobiazko
>> http://tapestry5.de
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Problems accessing Named Queries in multiple Persistent Units

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
I use persistense.xml.

I don't think  @Contribute(JpaEntityPackageManager.class)    public static void providePackages(Configuration<String> configuration)
is getting called, hence continuing of my frustrations.
Still need help with getting that resolved.

Thanks!

Here is my persistense.xml:
----------------
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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_2_0.xsd">
  <persistence-unit name="BillingPUTest" transaction-type="JTA">
    <jta-data-source>jdbc/BillingTest</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>

  <persistence-unit name="BillingPUProd" transaction-type="JTA">
    <jta-data-source>jdbc/BillingProd</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>
</persistence>


On Jul 12, 2011, at 11:15 AM, Igor Drobiazko wrote:

> Looks like named query is not know in the BillingPUTest persistence unit.
> How did you define it?
> 
> On Tue, Jul 12, 2011 at 2:19 PM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:
> 
>> I am using Tapestry 5.3 and the JPA module 5.3
>> 
>> In my Page class:
>> 
>> @PersistenceContext(unitName = "BillingPUTest") private EntityManager em;
>> 
>> @SuppressWarnings("unused")
>>   @PageAttached
>>   private void populate()
>>   {
>>   //   userList = facade.findAll();
>>       // either variant will work the same
>>      userList = em.createNamedQuery("Webusers.findAll",
>> Webusers.class).getResultList();
>>   }
>> 
>> When I have only one persistent unit in persistence.xml, everything works,
>> but once I add another unit (i.e. production database) I get the following
>> exception:
>> 
>> ava.lang.RuntimeException
>> Unable to attach page TapPage: NamedQuery of name: Webusers.findAll not
>> found.
>> java.lang.IllegalArgumentException
>> NamedQuery of name: Webusers.findAll not found.
>> Hide uninteresting stack framesStack trace
>> 
>> org.eclipse.persistence.internal.jpa.EJBQueryImpl.getDatabaseQueryInternal(EJBQueryImpl.java:576)
>> 
>> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1004)
>> 
>> org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1024)
>> com.baw.website.pages.TapPage.populate(TapPage.java:25)
>> com.baw.website.pages.TapPage.populate$access122fbc563a57e270(TapPage.java)
>> com.baw.website.pages.TapPage$Shim_122fbc563a57e26f.invoke(Unknown Source)
>> 
>> org.apache.tapestry5.internal.plastic.MethodHandleImpl.invoke(MethodHandleImpl.java:48)
>> It also works every time from a session bean, just not from an EM injected
>> into the tapestry page.
>> 
>> Please help!
>> 
>> 
> 
> 
> -- 
> Best regards,
> 
> Igor Drobiazko
> http://tapestry5.de


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org