Announcement Announcement Module
Collapse
No announcement yet.
I can't Understanding EntityManager code generated by Spring Roo Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • I can't Understanding EntityManager code generated by Spring Roo

    @PersistenceContext
    transient EntityManager entityManager;

    public static final EntityManager entityManager() {
    EntityManager em = new Food().entityManager;
    if (em == null)
    throw new IllegalStateException(
    "Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
    return em;
    }

    the code looks very suspicious.

    help me . very very Thanks you . and bless you

  • #2
    Since entityManager() is static it has to create an instance of Food otherwise DI would not work (via AspectJ due to using new and not getBean()). Then it checks if the em exists and returns it.

    Comment


    • #3
      thanks . I decomplier the Food.class I understand

      Originally posted by spgmx View Post
      Since entityManager() is static it has to create an instance of Food otherwise DI would not work (via AspectJ due to using new and not getBean()). Then it checks if the em exists and returns it.
      thank you replay.

      the Clear reasons

      Code:
      	public Shop() {
      		JoinPoint joinpoint1 = Factory.makeJP(ajc$tjp_11, this, this);
      		JoinPoint joinpoint = Factory.makeJP(ajc$tjp_0, this, this);
      		if (this != null && getClass().isAnnotationPresent(Configurable) && AnnotationBeanConfigurerAspect.ajc$if$bb0((Configurable) getClass().getAnnotation(Configurable))) {
      
      			AnnotationBeanConfigurerAspect.aspectOf().ajc$before$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$1$e854fa65(this);
      		}
      
      		if (this != null && getClass().isAnnotationPresent(Configurable) && (this == null || !getClass().isAnnotationPresent(Configurable) || !AnnotationBeanConfigurerAspect.ajc$if$bb0((Configurable) getClass().getAnnotation(Configurable))) && AbstractDependencyInjectionAspect.ajc$if$6f1(joinpoint)) {
      			
      			AnnotationBeanConfigurerAspect.aspectOf().ajc$afterReturning$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$2$1ea6722c(this);
      		}
      		if (!AnnotationBeanConfigurerAspect.ajc$if$bb0((Configurable) getClass().getAnnotation(Configurable)) && AbstractDependencyInjectionAspect.ajc$if$6f1(joinpoint1)) {
      
      			AnnotationBeanConfigurerAspect.aspectOf().ajc$afterReturning$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$2$1ea6722c(this);
      		}
      	}
      
      	public static final EntityManager entityManager() {
      		JoinPoint joinpoint = Factory.makeJP(ajc$tjp_1, null, null);
      		if (AnnotationDrivenStaticEntityMockingControl.ajc$cflowCounter$1.isValid() && AnnotationDrivenStaticEntityMockingControl.hasAspect())
      			return (EntityManager) entityManager_aroundBody1$advice(joinpoint, AnnotationDrivenStaticEntityMockingControl.aspectOf(), null, ajc$tjp_1, joinpoint);
      		else
      			return entityManager_aroundBody0(joinpoint);
      	}
      
      	private static final EntityManager entityManager_aroundBody0(JoinPoint joinpoint) {
      		EntityManager em = (new Shop()).entityManager;
      		if (em == null)
      			throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
      		else
      			return em;
      	}
      
      	private static final Object entityManager_aroundBody1$advice(JoinPoint thisJoinPoint, AbstractMethodMockingControl ajc$aspectInstance, AroundClosure ajc$aroundClosure, org.aspectj.lang.JoinPoint.StaticPart thisJoinPointStaticPart, JoinPoint thisJoinPoint) {
      		if (AbstractMethodMockingControl.ajc$inlineAccessFieldGet$org_springframework_mock_staticmock_AbstractMethodMockingControl$org_springframework_mock_staticmock_AbstractMethodMockingControl$recording(ajc$aspectInstance)) {
      			AbstractMethodMockingControl.ajc$inlineAccessFieldGet$org_springframework_mock_staticmock_AbstractMethodMockingControl$org_springframework_mock_staticmock_AbstractMethodMockingControl$expectations(ajc$aspectInstance).expectCall(thisJoinPointStaticPart.toLongString(), thisJoinPoint.getArgs());
      			return null;
      		} else {
      			return AbstractMethodMockingControl.ajc$inlineAccessFieldGet$org_springframework_mock_staticmock_AbstractMethodMockingControl$org_springframework_mock_staticmock_AbstractMethodMockingControl$expectations(ajc$aspectInstance).respond(thisJoinPointStaticPart.toLongString(), thisJoinPoint.getArgs());
      		}
      	}

      Comment

      Working...
      X