World.java 695 B

123456789101112131415161718192021222324252627282930
  1. package models;
  2. import play.db.jpa.JPA;
  3. import javax.persistence.Column;
  4. import javax.persistence.Entity;
  5. import javax.persistence.Id;
  6. import java.util.List;
  7. @Entity
  8. public class World {
  9. @Id
  10. public Long id;
  11. @Column(name = "randomNumber")
  12. public Long randomNumber;
  13. public static World findById(final Long id) throws Throwable {
  14. return JPA.withTransaction("default", true, () -> JPA.em().find(World.class, id));
  15. }
  16. public static List<World> save(final List<World> worlds) throws Throwable {
  17. for (final World world : worlds) {
  18. JPA.withTransaction("default", false, () -> JPA.em().merge(world));
  19. }
  20. return worlds;
  21. }
  22. }