Git Product home page Git Product logo

simplejpa's Introduction

#Jayther's SimpleJPA Fork# Note: this is more for myself so it's easy for me to work with JPA-style configurations.

Improvements include only depending on member fields, splitting long strings to multiple attribute/value pairs (from appoxy#5 , adapted to work in SimpleJPA's more recent changes), and serialize objects into Base64 strings (which also use the long string split feature).

WARNING: Foreign keys and Lobs support are removed for now to remove dependencies on beans and enhancers. Will re-add support when I have time.

WARNING: There are some commented/removed code in the tests. Will add proper tests for the major changes.

#SimpleJPA's new home.#

Discussion Group: http://groups.google.com/group/simplejpa

##Introduction## Here's how to get started using SimpleJPA.

##Dependencies## Starting with version 1.5 SimpleJPA switched to use Amazon's Java SDK. Use the latest releases of (I'll try to package these up into the release if I can figure out the licensing compatability):

  • commons-lang - You can grab all commons libs at http://commons.apache.org/downloads/index.html
  • commons-collections
  • commons-logging
  • commons-codec
  • cglib-nodep
  • kitty-cache
  • ehcache
  • scannotation
  • javassist (required for scannotation)
  • ejb3-persistence-api
  • AWS SDK for Java
  • Apache HttpClient

When building from source and using the Maven pom.xml file Kitty-cache will need to be added explicitly as a reference.

Dependencies for versions pre 1.5

##Setup## Create a file called simplejpa.properties and put on the classpath. Add your Amazon access key and secret key like:

accessKey = AAAAAAAAAAAAAAAAAAAAAAA
secretKey = SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS

For more configuration options, see Configuration.

Now the Code Create an EntityManagerFactory // Create EntityManagerFactory. This should be a global object that you reuse. private static EntityManagerFactoryImpl factory = new EntityManagerFactoryImpl("persistenceUnitName", null); Get EntityManager's from the Factory // Get an EntityManager from the factory. This is a short term object that you'll use for some processing then throw away EntityManager em = factory.createEntityManager(); ##Persisting an object## Lets create a very simple object to store.

@Entity
public class MyTestObject {
	@Id
	private String id;
	private String name;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
   
	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

}

Now to persist it:

MyObject ob = new MyObject();
ob.setName("Scooby doo");
em.persist(ob);

That's it!

##Querying## See JPAQuery

##Deleting## MyObject ob... em.remove(ob); Close the EntityManager when you're done This is done after you've completed a set of tasks, such as displaying a web page. It ensures that caches get cleaned up and no memory gets wasted.

em.close();

Close the EntityManagerFactory before you shutdown your app factory.close(); ##What Next?## See all the JPA features currently supported. Cast your EntityManager to SimpleEntityManager to get more advanced features like asynchronous operations. Use our ready to go BaseClasses so you can write less code

simplejpa's People

Contributors

aldrinleal avatar andrewkl avatar benjchristensen avatar cast avatar cbolduc avatar grouchal avatar jayther avatar kerrywright avatar treeder avatar

Watchers

 avatar  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.