JPAで複数のDBを使用したいときに、このような設定がよくされる。
<persistence-unit name="OBIC_PU" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <class>jp.co.irep.tech.uriagegenkadataaccumulator.entity.VWKeiyakuKihonJouhou</class> <class>jp.co.irep.tech.uriagegenkadataaccumulator.entity.VWGenkaiShousai</class> <class>jp.co.irep.tech.uriagegenkadataaccumulator.entity.VWGenkaMeisai</class> <class>jp.co.irep.tech.uriagegenkadataaccumulator.entity.VWUriageShousai</class> <class>jp.co.irep.tech.uriagegenkadataaccumulator.entity.VWUriageMeisai</class> <properties> <property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://192.168.1.42"/> <property name="javax.persistence.jdbc.password" value="zStore_user"/> <property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/> <property name="javax.persistence.jdbc.user" value="******"/> </properties> </persistence-unit> <persistence-unit name="DEST_PU" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <class>jp.co.irep.tech.uriagegenkadataaccumulator.entity.GenkaShousai</class> <class>jp.co.irep.tech.uriagegenkadataaccumulator.entity.UriageShousai</class> <class>jp.co.irep.tech.uriagegenkadataaccumulator.entity.GenkaMeisai</class> <class>jp.co.irep.tech.uriagegenkadataaccumulator.entity.UriageMeisai</class> <class>jp.co.irep.tech.uriagegenkadataaccumulator.entity.KeiyakuKihon</class> <properties> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://172.17.8.59:3306/irepdb?zeroDateTimeBehavior=convertToNull"/> <property name="javax.persistence.jdbc.password" value="******"/> <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> <property name="javax.persistence.jdbc.user" value="testuser"/> </properties> </persistence-unit>
この設定で、下記のエラーが出るはずです。
java.lang.RuntimeException: javax.annotation.processing.FilerException: Attempt to recreate a file for type com.bss.easycooking.libdataeasycooking2.entity.BaseRicette_ at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.process(CanonicalModelProcessor.java:407) at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793) at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722) at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97) at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029) at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163) at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108) at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824) at com.sun.tools.javac.main.Main.compile(Main.java:439) at com.sun.tools.javac.main.Main.compile(Main.java:353) at com.sun.tools.javac.main.Main.compile(Main.java:342) at com.sun.tools.javac.main.Main.compile(Main.java:333) at com.sun.tools.javac.Main.compile(Main.java:94) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.codehaus.plexus.compiler.javac.JavacCompiler.compileInProcess(JavacCompiler.java:554) at org.codehaus.plexus.compiler.javac.JavacCompiler.compile(JavacCompiler.java:161) at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:605) at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) Caused by: javax.annotation.processing.FilerException: Attempt to recreate a file for type com.bss.easycooking.libdataeasycooking2.entity.BaseRicette_ at com.sun.tools.javac.processing.JavacFiler.checkNameAndExistence(JavacFiler.java:522) at com.sun.tools.javac.processing.JavacFiler.createSourceOrClassFile(JavacFiler.java:396) at com.sun.tools.javac.processing.JavacFiler.createSourceFile(JavacFiler.java:378) at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.generateCanonicalModelClass(CanonicalModelProcessor.java:98) at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.generateCanonicalModelClasses(CanonicalModelProcessor.java:226) at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.process(CanonicalModelProcessor.java:403)
対策としては2つのPUをはっきり分けないといけないということ。
<persistence-unit name="Bar"> <properties> <property name="eclipselink.canonicalmodel.subpackage" value="one"/> </properties> </persistence-unit> <persistence-unit name="Bar2"> <properties> <property name="eclipselink.canonicalmodel.subpackage" value="two"/> </properties> </persistence-unit>