且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

OpenJPA和Spring-boot配置

更新时间:2022-06-20 18:07:54

此处是pom条目,用于在构建时增强实体类.它为我工作. 还请注意,在构建时需要META-INF/persistence.xml来增强类,而在运行时则不需要.因此,您可以在创建jar时排除persistence.xml.

Here is pom entry to enhance the entity classes at build time. It worked for me. Also please note that you need META-INF/persistence.xml to enhance the classes at build time and during runtime it is not required. So you can exclude persistence.xml while creating jar.

    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.openjpa</groupId>
                                    <artifactId>openjpa-maven-plugin</artifactId>
                                    <versionRange>2.2.0</versionRange>
                                    <goals>
                                        <goal>enhance</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                    <includes>**/domain/*.class</includes>
                    <addDefaultConstructor>true</addDefaultConstructor>
                    <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

    <plugins>
        .....
        <plugin>
            <groupId>org.apache.openjpa</groupId>
            <artifactId>openjpa-maven-plugin</artifactId>
            <version>2.2.0</version>
            <configuration>
                <includes>**/domain/*.class</includes>
                <addDefaultConstructor>true</addDefaultConstructor>
                <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
                <persistenceXmlFile>${project.basedir}/src/main/resources/META-INF/persistence.xml</persistenceXmlFile>
            </configuration>
            <executions>
                <execution>
                    <id>enhancer</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>enhance</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

    </plugins>

</build>