10 Replies Latest reply on May 13, 2009 8:07 AM by nickarls

    Might be something simple, JPA?

    meetoblivion

      I've got what I figure should be a pretty simple question, how exactly do you inject an entity manager? Is it just bound via JNDI, and you have to tie the appropriate name somewhere?

        • 1. Re: Might be something simple, JPA?
          pmuir

          You have two option's in the latest release. Simplest option is to use @PersistenceContext (anywhere, not just in EJBs). Another option is to use the Java EE Resource injection. Add to your beans.xml:


          <EntityManager> 
            <PersistenceContext> 
              <unitName>CustomerDatabase</unitName> 
            </PersistenceContext> 
            <myapp:CustomerDatabase/> 
          </EntityManager>



          and inject as @CustomerDatabase EntityManager entityManager;

          • 2. Re: Might be something simple, JPA?
            gonorrhea

            So will Web Beans offer the equivalent of SMPC or not?  Or must we wait for Seam 3?


            And what about using Hibernate MANUAL flush with SMPC?  Will that be available in Web Beans or not?

            • 3. Re: Might be something simple, JPA?
              nickarls

              Well, someone has to write it first, is there a difference if it's in Web Beans extension or Seam 3? ;-) Don't know how politically correct it would be to bundle something Hibernate-specific with Web Beans. Well, if it would be an extension, perhaps it wouldn't matter. But if we make all Seam 3 modules JSR-299 pluggable and bundle them with Web Beans as extensions, there is not much of Seam left :-)

              • 4. Re: Might be something simple, JPA?
                gonorrhea

                It's possible to implement the spec (e.g. RI) and add extra functionality.  That's what the major middleware vendors do with JEE 5, for example.  Clustering is not part of the spec (AFAIK) but they add it on and it passes TCK...


                Well the idea was to have Web Beans form the core of Seam 3.  Ok, so what will happen to bijection in Seam 3, will it use Guice or not?

                • 5. Re: Might be something simple, JPA?
                  pmuir

                  I don't understand what Guice has got to do with it?


                  Seam 3 will be based on the 299 contexts and dependency injection.

                  • 6. Re: Might be something simple, JPA?
                    gonorrhea

                    ok, so are you saying that Seam 3 will not provide bijection capability (i.e. injection only, no outjection/disinjection)?

                    • 7. Re: Might be something simple, JPA?
                      nickarls

                      Arbi Sookazian wrote on May 07, 2009 17:40:


                      ok, so are you saying that Seam 3 will not provide bijection capability (i.e. injection only, no outjection/disinjection)?


                      There are hidden ways but we won't tell anyone so they won't abuse it :-P

                      • 8. Re: Might be something simple, JPA?
                        gavin.king

                        In the next rev of the 299 spec, the way to declare an injectable persistence context is:


                        public class Anything {
                        
                           @Produces @PersistenceContext(unitName="MyDatabase")
                           @MyDatabase EntityManager em;
                        
                        }




                        Then you can inject it with:


                        @MyDatabase EntityManager em;



                        The same pattern applies for all other EE resourcey type things.


                        I want Seam to support the following:


                        public class Anything {
                        
                           @Produces @ConversationScoped 
                           @PersistenceContext(unitName="MyDatabase", type=EXTENDED)
                           @MyDatabase EntityManager em;
                        
                        }



                        To get a conversation-scoped PC. But I doubt this will make it into 299.

                        • 9. Re: Might be something simple, JPA?
                          meetoblivion

                          isn't the issue w/ that approach more about the requirements of EXTENDED rather than capabilities of 299? (you know, fix JPA..)

                          • 10. Re: Might be something simple, JPA?
                            nickarls

                            Nah, as I see it, JPA is fine. It provides and extended persistence context. It is up to other layers to determine the lifecycle as to how extended it is