Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FilerException when building Java EE 6 Project

I have a Java EE 6 Project in Netbeans 7 which runs fine when I compile and start it in the IDE. However, when I clean and build the project, I am getting a

java.lang.RuntimeException: javax.annotation.processing.FilerException: Attempt to recreate a file for type {myclass}

(where myclass is always a JPA entity class).

Which entity class it is changes if I change something in the code.

I have no clue what might cause this error - can anyone provide an idea what to look at.

The only extra lib I am using is Velocity.

Update: I am using two persistence units on the same database, one 'normal' one and one non transactional one. The non-transactional one I use for logging things to the database; with a commit after each insert of a log event.

When I change that and only use the one 'normal' PU, the project compiles fine. Could it be that the two PUs interfere with some optimization done by eclipselink?

Here is the beginning of the stack trace:

An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.RuntimeException: javax.annotation.processing.FilerException: Attempt to recreate a file for type de.guj.contenthub.ftdts.entity.AgofEntry_
    at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.process(CanonicalModelProcessor.java:407)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:625)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:554)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:699)
    at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:981)
    at com.sun.tools.
like image 518
Jan Algermissen Avatar asked Jan 20 '12 09:01

Jan Algermissen


4 Answers

Having two persistence units using the same Entity class did seem to be the problem.

In my case I had one unit for querying data and the other for authentication. The one for authentication does not need to know about my Entity classes, so in Netbeans I had to uncheck the "Include All Entity Classes in "MyWebServiceProject" Module".
Or add:

<exclude-unlisted-classes>true</exclude-unlisted-classes>

to the web.xml file for that persistence unit.

like image 63
ecurb33 Avatar answered Nov 16 '22 14:11

ecurb33


I got this solved by setting

<property name="eclipselink.canonicalmodel.subpackage" value="foobar"/>

for each persistence unit in persistence.xml. The value has to be unique for each unit. The classes are then generated into different packages, eg. com.mycompany.foo.PojoOne_ and com.mycompany.bar.PojoOne_ instead of just com.mycompany.PojoOne_.

Source

like image 44
miq Avatar answered Nov 16 '22 13:11

miq


The answser is to make this in the persistence.xml file;

<persistence-unit name="prod_PU">
   <properties>
    <property name="eclipselink.canonicalmodel.subpackage" value="prod"/>
   </properties>
</persistence-unit>
<persistence-unit name="dev_PU">
   <properties>
      <property name="eclipselink.canonicalmodel.subpackage" value="dev"/>
   </properties>
</persistence-unit>

For example, the packages for the entity1 will be generated as :

entity1.prod
entity1.dev
like image 7
bilelovitch Avatar answered Nov 16 '22 14:11

bilelovitch


It seems, the problem is that I use one and the same entity class in two different persistence units. I am not sure whether this forbidden by JPA in general or is only a problem with eclipselink.

One 'solution' I found then is to duplicate my entity class. Not nice, but works for now.

More answers still welcome.

like image 4
Jan Algermissen Avatar answered Nov 16 '22 13:11

Jan Algermissen