Results 1 to 10 of 11

Thread: Entity manager has not been injected

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    6

    Default Entity manager has not been injected

    Hi,
    I'm trying to implement a simple application. I have a simple class (I took it from http://blog.springsource.com/2009/05/27/roo-part-2/)

    Code:
    @Entity
    @RooJavaBean
    @RooToString
    @RooEntity
    public class Rsvp {
    
        @NotNull
        @Size(min = 1, max = 30)
        private String code;
    
        @Size(max = 30)
        private String email;
     }
    and then implemented some other class that uses it

    Code:
    public class MyApplication {
    
    	public static void main(String params[]) {
    		MyApplication myApp = new MyApplication();
    		myApp.startMyApp();
    	}    
    
    	public void startMyApp() {
    		Rsvp rsvp = new Rsvp();
    		rsvp.setEmail("Email");
    		System.out.println("Test Rsvp email: " + rsvp.getEmail());
    		rsvp.persist();
    	}
    }
    When I run it the line "rsvp.persist();" throws an exception "Exception in thread "main" java.lang.IllegalStateException: Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)" In a debug mode I see that entityManager is not injected.

    I use SpringSource Tool Suite 2.1.0.SR01 with Eclipse AspectJ Development Tools 2.0.1.e35x-20091001-1600 and included the following libraries in my project

    aspectjweaver-1.6.3.jar
    org.springframework.beans-3.0.0.RC1.jar
    com.springsource.org.aspectj.tools-1.6.5.RELEASE.jar
    org.springframework.jdbc-3.0.0.RC1.jar
    com.springsource.org.apache.commons.dbcp-1.2.2.osgi.jar
    com.springsource.javax.transaction-1.1.0.jar
    com.springsource.javax.validation-1.0.0.CR3.jar
    com.springsource.org.hibernate.validator-4.0.0.Beta2.jar
    com.springsource.slf4j.api-1.5.6.jar
    com.springsource.javax.persistence-1.0.0.jar
    com.springsource.slf4j.log4j-1.5.6.jar
    com.springsource.edu.emory.mathcs.backport-3.1.0.jar
    ehcache-1.3.0.jar
    com.springsource.org.hibernate.ejb-3.3.2.GA.jar
    hibernate-annotations-3.3.1.ga.jar
    com.springsource.com.mysql.jdbc-5.1.6.jar
    org.springframework.transaction-3.0.0.RC1.jar
    org.springframework.aop-3.0.0.RC1.jar
    org.springframework.context-3.0.0.RC1.jar
    org.springframework.roo.annotations-1.0.0.RC2.jar
    com.springsource.org.aspectj.runtime-1.6.5.RELEASE.jar
    com.springsource.org.hibernate-3.2.6.ga.jar
    org.springframework.orm-3.0.0.RC1.jar
    spring-jpa-2.0.6.jar
    aspectjrt-1.6.5.jar
    hibernate-entitymanager.jar
    dbpopulator-0.1.0-SNAPSHOT.jar
    org.springframework.core-3.0.0.RC1.jar
    org.springframework.aspects-3.0.0.RC1.jar
    com.springsource.org.apache.commons.logging-1.1.1.jar
    org.springframework.beans-3.0.0.RC1.jar
    org.springframework.core-3.0.0.RC1.jar
    org.springframework.aspects-3.0.0.RC1.jar
    aspectjweaver-1.6.3.jar
    org.springframework.transaction-3.0.0.RC1.jar
    com.springsource.org.apache.commons.logging-1.1.1.jar
    commons-lang-2.4.jar

    I read that the reason could be the absence of an aspects library. I also tried to add org.springframework.aspects-3.0.0.RC1.jar to the "AspectJ Build->Aspect path". Nothing helps

  2. #2
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    Roo uses Spring Framework's @Configurable support. For @Configurable to work, the Spring Framework needs to have been initialized. So try adding a new ClasspathXmlApplicationContext("classpath*:META-INF/spring/applicationContext*.xml) to the start of your main method.

    A good test is to run the generated integration tests. These prove that AJDT/AspectJ is working OK.

    I'm actually surprised you're using a main method rather than running up a webapp. Is that for experimentation, or were you building a console or standalone-style app?
    Ben Alex
    Project Founder, Spring UAA, Spring Roo and Spring Security

  3. #3
    Join Date
    Oct 2009
    Posts
    6

    Default

    Hi, Ben,
    Many thanks for answering. You're 100% right! I did forget to initialize a context. It was so stupid to forget that! I ran integration tests and they were ok. Now it's clear why and what happened.
    I used a main method just to experiment with Roo. However, I'm going to use Roo for my Swing application.

  4. #4
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    Using Roo for Swing. Interesting. If you get a chance to post a blog or article on that, please point me to it as I am sure others would be interested in reading more....
    Ben Alex
    Project Founder, Spring UAA, Spring Roo and Spring Security

  5. #5
    Join Date
    Mar 2009
    Posts
    19

    Default

    > Using Roo for Swing. Interesting.

    Indeed. How hard would it be to replace the web layer with a desktop app?

    Further, how hard would it be for Roo to generate RESTful services and a Swing-based JNLP application to invoke them? Doable I guess.

    Btw. how does the Swing threading model (Swing/AWT components should only be created/manipulated from within the EDT) work with the Spring DI container?

    --
    Jukka

  6. #6
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    Most people startup the Spring DI container from within their main method before starting to paint any widgets. You might like to look at the Spring Rich Client Project for ideas, as they specialize in Swing in that project.

    Roo already creates REST endpoints so it wouldn't be hard to access them from a Swing client, especially when combined with Spring 3's client-side RestTemplate. You might also want to consider HttpInvoker if you just want plain old remoting.
    Ben Alex
    Project Founder, Spring UAA, Spring Roo and Spring Security

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •