Skip to content

Instantly share code, notes, and snippets.

@scompt
Created April 8, 2011 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scompt/909935 to your computer and use it in GitHub Desktop.
Save scompt/909935 to your computer and use it in GitHub Desktop.
package controllers;
import play.*;
import play.mvc.*;
import java.util.*;
import models.*;
import jobs.*;
public class Application extends Controller {
public static void index() {
Blah blah = new Blah();
blah.name = "woo";
blah.save();
blah.em().flush(); // with or without, same result
// Works, but then I have to reload all of my entities
// JPAPlugin.closeTx(false); JPAPlugin.startTx(false);
//
// blah.name = "woo2";
// blah.save();
new DumbJob(blah.id).now();
new DumbJob(blah.id).in(5);
render();
}
}
package models;
import play.db.jpa.Model;
import javax.persistence.*;
@Entity
public class Blah extends Model {
public String name;
}
package jobs;
import play.jobs.Job;
import models.Blah;
public class DumbJob extends Job {
private long id;
public DumbJob(long id) {
this.id = id;
}
@Override
public void doJob() {
System.out.println("ID: " + id);
System.out.println("Found: " + Blah.findById(id));
}
}
16:18:54,361 INFO ~ Application 'tester' is now started !
ID: 7
Found: null
ID: 7
Found: Blah[7]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment