4

On a clean installation of Eclipse Kepler 4.3.2, with an installation not including anything like JPA aspects, Spring, whatever - just plain Java, I keep encountering this weird issue.

Upon building the project, but not running it even once, the file bin/META-INF/persistence.xml is constantly in use. Eclipse refuses to rebuild the project because of it, and I can't delete the file while Eclipse is running.

This locking does not happen to any other (XML) file in the same folder, or any file in any other folder. Just that one file. Since Eclipse without any Hibernate or JPA tools installed should have no concept of the importance of this file, why does this happen? Not even the original source file is locked!

How can I debug this?

Cilph
  • 115
  • 2
  • 8

4 Answers4

1

What worked for me (I'm working with an EAR project > EJB module) was moving all configuration files from prj-root/src/META-INF to a prj-root/resources/META-INF folder, then I modified my Ant script accordingly to generate the assemblies.

EDIT: This happens when using hibernate-jpamodelgen to generate the entities' static metamodel. Upgrade to at least 4.3.9 and you'll get rid of the problem (see https://hibernate.atlassian.net/browse/HHH-9528).

jpangamarca
  • 713
  • 2
  • 13
  • 33
1

I presume you use Windows. Like jpangamarca mentioned, I have the same problem with Eclipse Luna and came up with a temporary solution before it is addressed by Eclipse itself.

How can I debug this?

I used Process Explorer to find out which process is locking my xml files. In the application, go to menu Find -> Find Handle or DLL... (Ctrl + F), fill in your file path, it will list all processes using your file. It is likely eclipse.exe in this case. You can then go back to the main screen, select the file in the lower panel and right click then choose Close Handle (or hit Delete).

I wrote a little batch file to do this conveniently whenever I feel necessary:

@echo off
for /f "tokens=3,6,8 delims=: " %%i in ('handle -p eclipse e:\git\ ^| grep ".xml\|.xmi\|.htm"') do echo Releasing %%k & handle -c %%j -y -p %%i

(replace e:\git\ with your path to limit scope of damage, using grep to only release locks on specific file types)

For the batch to work, you need the following utilities available in your system path:

For windows with UAC (win 7/8), you will need to run it as administrator. Or else it will tell you to.

t7tran
  • 1,899
  • 1
  • 18
  • 16
1

This happened to me and in my case the root cause was Hibernate JPA 2 Metamodel Generator: https://docs.jboss.org/hibernate/jpamodelgen/1.0/reference/en-US/html_single/

The only solution I found is to use EclipseLink's Canonical Model Generation https://wiki.eclipse.org/UserGuide/JPA/Using_the_Canonical_Model_Generator_%28ELUG%29

karmapolice
  • 326
  • 2
  • 11
0

The handle script worked for me, but maybe it was my process i had to search for javaw instead of eclipse.

BryanStopp
  • 88
  • 5