MyEclipse Forums
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
sweepy
Post subject: Scaffolding problem due to EntityManager empty unitName  PostPosted: Apr 10, 2011 - 03:48 PM
Registered Member
Registered Member


Joined: Oct 22, 2008
Posts: 56

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:
Code:

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

rather than...
Code:

   /**
    * 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:
Code:

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.[/code]

_________________
Thanks!
Peter
 
 View user's profile Send private message  
Reply with quote Back to top
jkennedy
Post subject: Scaffolding problem due to Entity Manager empty unit name  PostPosted: Apr 11, 2011 - 07:20 PM



Joined: Jan 27, 2010
Posts: 245

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
 
 View user's profile Send private message  
Reply with quote Back to top
sweepy
Post subject: RE: Scaffolding problem due to Entity Manager empty unit nam  PostPosted: Apr 16, 2011 - 02:09 PM
Registered Member
Registered Member


Joined: Oct 22, 2008
Posts: 56

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).

http://www.myeclipseide.com/PNphpBB2-viewtopic-t-27142.html

_________________
Thanks!
Peter
 
 View user's profile Send private message  
Reply with quote Back to top
sweepy
Post subject: RE: Scaffolding problem due to Entity Manager empty unit nam  PostPosted: May 08, 2011 - 02:43 PM
Registered Member
Registered Member


Joined: Oct 22, 2008
Posts: 56

Tested. Works...thanks mate.

_________________
Thanks!
Peter
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits