facebook

Scaffolding problem due to EntityManager empty unitName

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #315910 Reply

    Peter
    Member

    Hi,

    I am using ME4S 9. Using DSL to scaffold a simple 2 table database, but the unitName is not being scaffolded in the DAOs.

    Every DAO generated has the following:

    
        /**
         * EntityManager injected by Spring for persistence unit 
         *
         * @generated
         */
        @PersistenceContext(unitName = "")
        private EntityManager entityManager;
    

    rather than…

    
        /**
         * EntityManager injected by Spring for persistence unit 
         *
         * @generated
         */
        @PersistenceContext(unitName = "NameHere")
        private EntityManager entityManager;
    

    Now this isn’t a problem and runs fine if I am using only one database, but when I use multiple databases it crashes and spits out a whole host of errors with the cause of all being:

    
    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 2
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:536)
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:495)
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:656)
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:629)
        at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:338)
        ... 50 more
    

    This problem does not occur in version ME4S 8.6. Please advise.

    #315947 Reply

    jkennedy
    Member

    Peter,

    You have uncovered a defect in MyEclipse for Spring 9.0. The underlying problem is that one of the tags we use in our code templates (actually this tag is used exclusively in this location) was packaged incorrectly
    and so it is not correctly emitting the Persistence Unit name.

    I will log the issue so that it can be picked up the next time we do an update, but if you would like to resolve the issue yourself in the mean time, you can using our template customization capability.

    I am including an example “customization project” that contains this specific template with a modified approach to getting the persistence unit name.

    If you are not familiar with the template customization feature, you can review a short video on the subject here: http://www.youtube.com/watch?v=LvrUT1Tl0VU

    To try this project out, you should be able to follow these steps:
    1. Choose File / Import / General / Existing Project into workspace
    2. Choose “Archive File” radio button and navigate to the .zip file from this post
    3. Finish the import

    You can look at the project to see the single template file. You will also notice a comment in the template that reads:

    An example of using the template customization ability to correct a known issue with getting the persistence unit name

    Now that you have the project in your workspace, right click on your DSL project and go to properties and type in “customization” in the search at the top to get to the MyEclipse Code Customization properties.

    Then just select this project and click OK.

    Once you touch the DAO in the DSL editor (just add to the comments and then click off the comments and click save) you will notice that your generated dao should have the appropriate Persistence Unit name now, along with the comment mentioned above.

    Let me know if you are not able to get the issue resolved.

    Thanks,
    Jack

    Attachments:
    You must be logged in to view attached files.
    #316101 Reply

    Peter
    Member

    Thanks heaps for that Jack! Unfortunately i have not been able to test this due to the below error that keeps occuring (which i think is completely unrelated).

    https://www.genuitec.com/forums/topic/generation-job-failed/

    #316643 Reply

    Peter
    Member

    Tested. Works…thanks mate.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Scaffolding problem due to EntityManager empty unitName

You must be logged in to post in the forum log in