2 Replies Latest reply on Jun 12, 2009 9:54 AM by gonorrhea

    more binding types

    gonorrhea



      For example, this is neither typesafe, nor very readable:

      @PersistenceContext(unitName="userDB") EntityManager em;



      So in JSR-299, you can write this instead:

      @UserDatabase EntityManager em;





      that's from GKing's latest in.relation.to post.


      I'm still struggling with binding types.


      Perhaps the definition of the binding type for @UserDatabase is as follows:


      @Retention(RUNTIME)
      @Target({TYPE, METHOD, FIELD, PARAMETER})
      @BindingType
      public @interface UserDatabase{}



      So how does @UserDatabase become a replacement for @PersistenceContext all of a sudden?


      ie. how does the container know to inject an EntityManager instance with @UserDatabase?


      yes, I'm reading the spec, but I still don't get it...

        • 1. Re: more binding types
          graben

          Have you read the spec carefully? In chapter 1.3.3 for example you can read examples how to define producer methods that will do this job.


          @Produces
          @PersistenceContext(unitName="UserData")
          @UserDatabase EntityManager userDatabaseEntityManager;



          With this definition you can use @UserDatabase as binding type everywhere you wants to.


          • 2. Re: more binding types
            gonorrhea

            your example makes sense, thx.