On Tue, Jul 12, 2011 at 9:53 PM, Lenny Primak <lpri...@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 <lpri...@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 <lpri...@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-unsubscr...@tapestry.apache.org
> >> For additional commands, e-mail: users-h...@tapestry.apache.org
> >>
> >>
> >
> >
> > --
> > Best regards,
> >
> > Igor Drobiazko
> > http://tapestry5.de
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de

Reply via email to