1 2 Previous Next 20 Replies Latest reply on Jan 3, 2010 3:12 PM by Kristof Vanbecelaere

    Ambiguous resolution

    Kristof Vanbecelaere Newbie

      I started off using a weld sample generated via the maven archetypes.


      Then I added some functionality to create new widgets


      @Named
      public class WidgetCreator
      {
         @Inject
         @WidgetRepository
         EntityManager widgetRepository;
      
         @Inject
         private Widget newWidget;
      
         @Model
         @Produces
         Widget getNewWidget() {
            return new Widget();
         }
      
         public void persist() {
            widgetRepository.persist(newWidget);
         }
      



      Why does this lead to an ambiguous resolution?


      I went on to add names like this




      @Named
      public class WidgetCreator
      {
         @Inject
         @WidgetRepository
         EntityManager widgetRepository;
      
         @Inject
         @Named("newWidget")
         private Widget newWidget;
      
         @Model
         @Produces
         @Named("newWidget")
         Widget getNewWidget() {
            return new Widget();
         }
      
         public void persist() {
            widgetRepository.persist(newWidget);
         }
      



      This gives an exception when submitting the form and invoking the persist method.




      java.lang.IllegalArgumentException: Unknown entity: be.sample.Widget_$$_javassist_15
           at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:311)
           at be.sample.WidgetCreator.persist(WidgetCreator.java:28)
      



      It all looked pretty darn simple... Does any of this make sense?


      I am also confused by this sentence in the spec:



      entity beans are by nature non-contextual objects and may not be injected into other objects.


      This is exactly what many examples do (e.g. the logged in user to name just one).


      Some guidance would be appreciated.

        1 2 Previous Next