8

I am getting this error when I tried to use a JPA object created by Roo.

Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)

I have followed some online advice to add the spring-aspects.jar to aspectj path in Eclipse but I still get this error. Does anyone know how to solve this?

The environment I am using is Spring 3.0.5, Hibernate 3.6 and JBoss 6.0.0.Final.

skaffman
  • 398,947
  • 96
  • 818
  • 769
newguy
  • 5,668
  • 12
  • 55
  • 95

5 Answers5

1

Go to STS ROO console (right click in the project in STS, then Spring Tools, then Open Spring Roo) Type in the prompt perform clean (will perform Maven clean) Then type perform eclipse

It should work!

  • When I try this, I can't type in the prompt. The window shows "Roo installation 'Roo 1.2.1.RELEASE' points to non-existing path 'C:\SpringSource\spring-roo-1.2.1.RELEASE\'." – pete the pagan-gerbil Apr 09 '13 at 10:09
1

Looks like you haven't injected Entity Manager.

Webapps (possible causes):

  • You didn't add entity manager factory to your applicationContext.xml

Java Applications:

  • You didn't add entity manager factory to your applicationContext.xml
  • Wrong application initialization (see below)

    public class SampleApp {
        public static void main(String[] args) {
            SampleApp obj = new SampleApp();
    
            // Injecting dependencies into application
            ConfigurableApplicationContext applicationContext = 
                    new ClassPathXmlApplicationContext("<PATH-TO>/applicationContext.xml");
            applicationContext.registerShutdownHook();
            applicationContext.getBeanFactory().autowireBeanProperties(
                    obj, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
    
            // Do the work
        }
    }
    
João Melo
  • 726
  • 7
  • 8
1

I had this problem too, and found the answer here: http://whyjava.wordpress.com/2012/02/13/fixing-exception-entity-manager-has-not-been-injected-is-the-spring-aspects-jar-configured-as-an-ajcajdt-aspects-library/

In my case, I needed to create a file called <classname>_Roo_Configurable.aj with the following content:

privileged aspect <classname>_Roo_Configurable { declare @type: <classname>: @Configurable; }

This explained why existing classes worked but new ones that I had created did not. The _Configurable.aj file did not (and still does not) show up in the package explorer in STS.

(I know this answer is incredibly late but I hope it helps someone else!)

pete the pagan-gerbil
  • 3,136
  • 2
  • 28
  • 49
0

You have to create the repository for the indicate domain.

In roo-terminal run the follow script

es.

 repository jpa --interface ~.dao.MyDomainDAO --entity ~.domain.MyDomain
Flavio Troia
  • 2,451
  • 1
  • 25
  • 27
0

I was having this same issue and fixed it by doing Spring Tools | Enable Spring Aspects Tooling on my project.

My classes were generated by Roo and pushed in (I was having way too many issues with it), and I simply added them to a brand new Google Web Application Project I created (so it uses GAE's app layout with a war directory, and no Maven for anything, at least not yet).

minimo
  • 1,396
  • 1
  • 9
  • 9