Coder Social home page Coder Social logo

spring-boot-openjpa-postgres's Introduction

spring-boot-openjpa-postgres

This is a spring boot example application that uses openjpa with a postgres database. The main purpose of this app is to replace the JPA implemenation from hibernate to openjpa. In this example postgres is the DB of choice but could easily be replace by any other DB such as MySql, Oracle, H2 etc.

Loadtime Weaving Activated

With the use of openjpa enhancement to the source entity classes after they have been compiled is required and to do so the maven plugin openjpa-maven-plugin is introduced to do just that. For more on enhancing of entity classes visit here http://openjpa.apache.org/enhancement-with-maven.html. The spring-boot-maven-plugin needs to be configured for runtime enchancement as well.

	<plugin>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-maven-plugin</artifactId>
		<version>${spring.boot.version}</version>
		<dependencies>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>springloaded</artifactId>
				<version>1.2.4.RELEASE</version>
			</dependency>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-instrument</artifactId>
				<version>${spring.version}</version>
			</dependency>
		</dependencies>
		<configuration>					       	   
			<agent>${settings.localRepository}/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar</agent>					
			<agent>${settings.localRepository}/org/apache/openjpa/openjpa/${openjpa.version}/openjpa-${openjpa.version}.jar</agent>
		</configuration>
	</plugin>
	<plugin>
		<groupId>org.apache.openjpa</groupId>
		<artifactId>openjpa-maven-plugin</artifactId>
		<configuration>
			<includes>**/entity/*.class</includes>
			<addDefaultConstructor>true</addDefaultConstructor>
			<enforcePropertyRestrictions>true</enforcePropertyRestrictions>
			<sqlFile>src/main/resources/schema.sql</sqlFile>
			<persistenceXmlFile>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>
		<dependencies>
			<dependency>
				<groupId>org.apache.openjpa</groupId>
				<artifactId>openjpa</artifactId>
				<version>${openjpa.version}</version>
			</dependency>
		</dependencies>
	</plugin>

Unit Testing and Runtime Enhancing

In order for the unit test to run successful you will need to set up a java agent. If you are using eclipse IDE you will need to a startup parameters by opening the following: Run -> Run Configurations -> Your application -> Arguments. The “VM arguments” field is the place for adding the -javaagent startup parameter. See an example below where I'm using the Spring instrument jar that is located in my maven repository. You can replace ${user-home} with the path to your user home folder. ${spring.version} and ${openjpa.version} should be based on the versions of spring and openjpa you are using in your pom.xml respectively.

-javaagent:${user.home}.m2/repository/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar

or

-javaagent:"${user.home}/.m2/repository/org/apache/openjpa/openjpa/${openjpa.version}/openjpa-${openjpa.version}.jar"

spring-boot-openjpa-postgres's People

Contributors

pmgarvey007 avatar

Watchers

James Cloos avatar Amol Mali avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.