Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 352121

Summary: Converting existing JPA project to Persistent Bundle does not refresh the JPA model
Product: z_Archived Reporter: Kaloyan Raev <kaloyan>
Component: LibraAssignee: Project Inbox <libra.osgifacet-inbox>
Status: NEW --- QA Contact: Kaloyan Raev <kaloyan>
Severity: normal    
Priority: P3 CC: brian.vosburgh, cvgaviao, dimitar.giormov, neil.hauge, shaun.smith
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Whiteboard:

Description Kaloyan Raev CLA 2011-07-14 11:41:06 EDT
Prerequisites:
* Install the Libra OSGi facet from the p2 repository of latest maintenance build: http://download.eclipse.org/libra/maintenance/snapshot

Steps to reproduce:
1. Create new JPA project. 
2. Right-click on the project > Configure > Convert to OSGi Bundle project. 
3. Make sure the JPA project is selected and click Finish. This wizard will install the OSGi facet. 

As a result of installing the OSGi facet, the src/META-INF folder is moved to <project-root>/META-INF. See bug 341398 for details. But the JPA model is not refreshed properly. The JPA Content node is empty and tools like the JPA Diagram Editor does not work. 

Workaround:
1. Right-click on the project > Validate. This refreshes the JPA model, but leaves an error marker on the META-INF/persistence.xml file. 
2. Repeat again: Right-click on the project > Validate. This removes the error marker. 

As part of bug 341398 I tried to refresh the JPA model in the install delegate of the OSGi facet, but could not find the proper way to do this. I've tried lots of combination using the following API, but with no luck: 

  jpaProject.update(monitor);
  jpaProject.updateAndWait();
  jpaProject.synchronizeContextModelAndWait();
  JptJpaCorePlugin.rebuildJpaProject(project);
  ValidationFramework.getDefault().validate(new IProject[] { project }, false, false, monitor);
  ValidationFramework.getDefault().validate(project.getFile(new Path(OSGiBundleFacetUtils.PERSISTENCE_URI)), monitor);

Neil, Shaun, could you give a hint here?
Comment 1 Neil Hauge CLA 2011-07-14 12:24:37 EDT
Probably the easiest workaround (from a user perspective) would be a project clean, which should resolve any stale model/validation issues.  I would think that programatically the JptJpaCorePlugin.rebuildJpaProject(project) would have done the job.  Ideally we would be listening for this type of change and would be updating the project as required, but this is obviously not in place yet.

Give rebuildJpaProject another try and try to confirm that the rebuild is taking place at the right time.