This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 241666 - Fail to delete persistence.xml in META-INF folder
Summary: Fail to delete persistence.xml in META-INF folder
Status: RESOLVED WONTFIX
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 8.0
Hardware: PC Windows 7
: P3 normal with 5 votes (vote)
Assignee: Sergey Petrov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-10 22:51 UTC by jialu98
Modified: 2018-10-02 20:49 UTC (History)
6 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Maven based project which contains the error (16.37 KB, application/octet-stream)
2014-07-18 05:54 UTC, t3_chris
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jialu98 2014-02-10 22:51:49 UTC
I created a maven based JPA project with persistence.xml in META-INF folder. When I do "clean and build" or "clean", it fails to delete the persistence.xml. I am not able to delete it through windows explore either. I only can delete it when I restart netbeans. 
Thanks
Jia
Comment 1 Sergey Petrov 2014-02-11 09:10:05 UTC
what do you mean maven based with jpa and persistence?
I don't see any atomic action to create this environment, what action was used to produce persistence.xml?
Comment 2 Sergey Petrov 2014-02-11 11:13:58 UTC
please reopen with more details.

I have no problem with
create j2se or web maven project
create persistece unit with almost a;; defaults
select persistence.xml and remove
. success
Comment 3 t3_chris 2014-07-17 10:53:02 UTC
I have the same problem using Netbeans 8.0 on Windows 8.1.


When I open Netbeans and "clean" my project it works (one time). 
All subsequent "clean" or "clean & build" runs fail with the following message:

=========== Maven Output ===========
Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.4.1:clean (default-clean) on project CominottoBackendEJB: Failed to clean project: Failed to delete C:\Users\xxxx\Documents\Projects\Cominotto_MVN\CominottoBackendEJB\target\classes\META-INF\persistence.xml -> [Help 1]
====================================

Even when I try to delete "target\classes\META-INF\persistence.xml" via Windows Explorer while Netbeans is running the file is locked.

When I close Netbeans the file gets unlocked and I can manually delete it. As soon as I do one build in Netbeans the file is locked again.

What also works is closing Netbeans, restarting it and then do a "clean" (but this works exactly once).

Environment:
Product Version: NetBeans IDE 8.0 (Build 201403101706)
Java: 1.7.0_45; Java HotSpot(TM) 64-Bit Server VM 24.45-b08
Runtime: Java(TM) SE Runtime Environment 1.7.0_45-b18
System: Windows 8 version 6.2 running on amd64; Cp1252; en_GB (nb)
Comment 4 Sergey Petrov 2014-07-17 11:20:52 UTC
Still can't reproduce, tried web and j2se maven projects with open and closed persistence.xml editor, without deploy to gf4 and after deloy to gf4.
With bundled maven.

What project type is used?
What maven is usedd - bundled or another one?
Is server registered in the project, what server, is it started/project deployed?
Can you reproduce if create new project and add persistence.xml or it's reproducible with some old complex project only?
Comment 5 t3_chris 2014-07-17 12:36:04 UTC
What I did was migrating a formerly ant-based project to maven. Therefore I've created the Maven projects with File, New Project, Maven, Enterprise Application. 

Then I begun to build up dependencies and copy *.java files from the ant project to maven. So there is some complexity in the project.

The target server is "JBoss EAP 6.2.0".
I use the bundled Maven.
The server is registered in the Maven project and all it's modules.

Up to now I was not able to reproduce the error when starting a simple new project. But I'll keep on trying.
Comment 6 t3_chris 2014-07-18 05:54:44 UTC
Created attachment 148125 [details]
Maven based project which contains the error
Comment 7 t3_chris 2014-07-18 05:55:37 UTC
Update:
It seems that the problem is somehow related to the Hibernate JPA static metamodel generator. As soon as I have the following dependency in my POM the problem occurs:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-jpamodelgen</artifactId>
    <version>4.3.5.Final</version>
    <optional>true</optional>
</dependency>

If I use the bundled version of Maven outside the Netbeans IDE (on the command line) everything works. So it seems to be somehow related to the combination of Netbeans plus Metamodel generation.

I've been able to create a project which triggers the error, see attachment https://netbeans.org/bugzilla/attachment.cgi?id=148125
Comment 8 Sergey Petrov 2014-07-18 07:06:34 UTC
Outside of nb the entire application which build the project is closed afeter building, it may cause release of file handles, in case of internal execution just some part of code ends and if hibernate modelgen have some problems within, it may case these problems. But I may need additional evaluation.
Comment 9 Sergey Petrov 2014-07-18 12:25:01 UTC
I dn't kow why but I can't do any action on attached project build/clean/clean&buil just fails silently. project is marked as a project with probles for jbos--ee-api and for jpamodelgen as not present in local repository but I'm not sure it's related.
I've tried new maven ejb project and create persistence unit with bundled(since 8.0.1) hibernate 4.3.1, by default modelgen is added, I see static metamodel class is generated after build and I can rebuild without any problem.

I do not expect it's smth fixed in dev build, instead I may moss some details, but you can try dev build to verify.
Comment 10 t3_chris 2014-07-18 14:06:27 UTC
Just tried the uploaded project on a different machine. First I also get the "Resolve Project Problems..." mark, but after doing the first build it is gone (when the dependencies are downloaded).

The locking problem is the same, after the first build, the file persistence.xml remains locked and "Clean" fails.

I've just downloaded and set-up "NetBeans IDE Build 201407090001". The problem is the same in this version. So unfortunately not fixed in dev-build.

The problem does not occur when I use the dev-build version without JaveEE and Maven Enterprise Application Support.
Comment 11 Sergey Petrov 2014-07-18 15:01:13 UTC
ok, I suppose I need to setup jboss, as I miss it before
Comment 12 Sergey Petrov 2014-07-18 19:38:54 UTC
After jboss installation, I can build.
But also I can rebuild without any problem, an it's  possibke with jboss started and stopped/ with deploy on save enabled/disabled.Do you use win7?
jdk version?
any exceptions in message.log?
Comment 13 Sergey Petrov 2014-07-18 19:58:24 UTC
spaces in path, local version, os 32/64bit, jdk 32/64 bit?
Comment 14 Sergey Petrov 2014-07-21 13:51:04 UTC
this     - value: java.io.FileInputStream #2
 <- in     - class: java.io.BufferedInputStream, value: java.io.FileInputStream #2
  <- fInputStream     - class: com.sun.org.apache.xerces.internal.impl.XMLEntityManager$RewindableInputStream, value: java.io.BufferedInputStream #3
   <- stream     - class: com.sun.xml.internal.stream.Entity$ScannedEntity, value: com.sun.org.apache.xerces.internal.impl.XMLEntityManager$RewindableInputStream #2
    <- fCurrentEntity     - class: com.sun.org.apache.xerces.internal.impl.XMLEntityScanner, value: com.sun.xml.internal.stream.Entity$ScannedEntity #2
     <- fEntityScanner     - class: com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl, value: com.sun.org.apache.xerces.internal.impl.XMLEntityScanner #7
      <- fTempReader     - class: com.sun.xml.internal.stream.XMLInputFactoryImpl, value: com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl #1
       <- XML_INPUT_FACTORY (JNI global)     - class: org.hibernate.jpamodelgen.util.xml.XmlParserHelper, value: com.sun.xml.internal.stream.XMLInputFactoryImpl #2

It's nearest GC root(org.hibernate.jpamodelgen.util.xml.XmlParserHelper) for unclosed FileInpitStream, I'm not sure I can do smth, an least easily, you may need to remove modelgen dependency in case of hibernate. Set to P3 for now as woraround is easier the reload ide each time but may not be very good if you need static metamodel. Another option build should be started in separate vm, but I'm not expert in this approach.
Comment 15 t3_chris 2014-07-21 14:15:03 UTC
Removing modelgen is not really an option, cause it's needed for the Criteria Query API Queries.

Is the root cause in Hibernate's modelgen, or in Netbeans!

Would it make sense to open a bug at Hibernate's site?
Comment 16 Sergey Petrov 2014-07-21 14:26:43 UTC
See provided trace from head dump,
XmlParserHelper have static field which seems to keep streams, as it's static, even if there is no instances of XmlParserHelper, it may keep streams open if are not closed properly. In case of external execution all classes are unloaded when jvm is terminated, but not in case if smth is executed from withing another jvm. In my opinion t may have sense to file an issue against hibenrate modelgen.
Comment 17 Martin Janicek 2014-07-22 08:21:19 UTC
Oops, sorry I updated wrong issue :)
Changing it back.
Comment 18 Sergey Petrov 2014-07-22 10:12:23 UTC
on other side, it seems to be reproducible with maven projects only, it may mean classes loading may behave a bit different from ant projects and classes unloading may be affected.
Martin, do you know anything about this area?
Comment 19 Martin Janicek 2014-07-22 11:54:31 UTC
(In reply to Sergey Petrov from comment #18)
> on other side, it seems to be reproducible with maven projects only, it may
> mean classes loading may behave a bit different from ant projects and
> classes unloading may be affected.
> Martin, do you know anything about this area?

Sorry, not at all. Is there any easy way how to reproduce the issue? I could at least take a look if something comes to my mind.
Comment 20 t3_chris 2014-07-22 12:09:10 UTC
(In reply to Martin Janicek from comment #19)
> Is there any easy way how to reproduce the issue? I could
> at least take a look if something comes to my mind.

Reproduction should be fairly easy using the attachment "Maven based project which contains the error". Just use Netbeans with EE support enabled.
Comment 21 Martin Janicek 2014-07-22 12:14:19 UTC
Ye, I have done that. But I'm able to Build/Clean/Clean&Build how many times I want to and don't see any kind of error. What exact steps caused you the problem?
Comment 22 t3_chris 2014-07-22 12:26:15 UTC
I have it after the first build. So every goal which involves clean fails after there was one build.

Did the modelgen generate the classes for JPA entities in your case (just to be sure that it was invoked)?
Comment 23 Sergey Petrov 2014-07-22 12:28:58 UTC
yes, I wasn't able to reproduce initially too, if it's reproducible it should fail on second compilation, when 1st compilation was on clean project, if you have 2 successful compilation it will fail never with later attempts (at least in my attempts).
also do not forget to register jboss 6.2
Comment 24 Martin Janicek 2014-07-22 14:27:44 UTC
(In reply to t3_chris from comment #22)
> Did the modelgen generate the classes for JPA entities in your case (just to
> be sure that it was invoked)?

Yes, it did.

(In reply to Sergey Petrov from comment #23)
> also do not forget to register jboss 6.2

Ok I haven't done this before. I will give it a try
Comment 25 Martin Janicek 2014-07-22 15:52:19 UTC
Sorry, still the same situation. Can't reproduce and thus I'm afraid I can't help either :-/

What comes to my mind is to try to use different version of hibernate-jpamodelgen if you have suspicion that it might caused those problems. It's the easiest way how to find out if the problem is on our side or not.
Comment 26 ChristopherS 2014-08-06 11:24:36 UTC
I suffer the same problem. We have a maven project with several modules. Two modules have a persistence.xml, one of them is consistently locked by netbeans (when it's in the target folder after the build). Luckely I can just remove the jpa model gen dependency since it's not used in that module, which fixes the problem.

The problem must be within netbeans since I never had the problem when just doing a maven build command line.
Comment 27 cgsasommer 2014-08-14 12:14:02 UTC
Sometimes this effect occures when netbeans do the "background scaning of projects". After this operation a can clean via Aggregator project.
Comment 28 Sergey Petrov 2014-08-14 12:30:33 UTC
regarding #26 as I said, usage in an application which is closed after execution will release all file handles even if you have bugs with resource releasing, on other side internal usage may keep these handles, and it's hold by hibernate static field.

regarding #27 from quite limited information, it may be also another issue but may be the same.
Comment 29 jocafi 2014-08-26 12:07:20 UTC
Same error. Using   Win 7 - 64 bits and  Java SDK (build 1.7.0_55-b13)  - 64 bits
Maven is running under proxy.
All projects are running well with exception the projects with JPA/Hibernate. 
I have to restart Netbeans every time. It sucks my day !
I cannot delete the file manually too. 
Please, at least "Release" the file "persistence.xml" after compilation in order we can delete it manually.
Comment 30 Sergey Petrov 2014-08-26 13:21:42 UTC
org.hibernate.jpamodelgen.util.xml.XmlParserHelper
have static field which after some chain hold open FileInputStream for persistence.xml
I would say either it's a bug in hibernate of nb do not support hibernate modelgen(consider if issue may have workaround)
sorry, have no time to file corresponding hibernate issue so far
Comment 31 Martin Balin 2016-07-07 08:55:58 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss
Comment 32 dcueva 2018-10-02 20:49:18 UTC
Hi All.

I have the same problem in Netbeans 8.2

To solve I delete this dependency from my pom file.

<dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>hibernate-jpamodelgen-4.3.1.Final</artifactId>
            <version>SNAPSHOT</version>
            <scope>provided</scope>
</dependency>


Greetings.