Question

I am taking my first steps with play 2.1, so I did the JavaTodoList Tutorial on the playframework website. Everything worked as expected.

Next I changed the todolist to use a postgresql database running on my dev box. All I had to do was to change some settings in application.conf`

db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5432/todo"
db.default.user=todo
db.default.password=secretpassword

I refreshed the page, did database evolution, and again everything worked just fine.

Now I want to play to use hibernate-spatial to store location coordinates to every todolist item (in fact that could be any other location based item).

I added some libraris to the app /lib directory, namely:

  • hibernate-commons-annotations-4.0.1.Final.jar
  • hibernate-core-4.1.9.Final.jar
  • hibernate-spatial-4.0-M1.jar
  • jdbc-stdext-2.0.jar
  • jts-1.12.jar
  • postgis-jdbc-1.5.3.jar
  • postgresql-8.4-701.jdbc4.jar

I used the same libraries on a classic glassfish java app to store spatial features, so they fit together. Also the postgresql database is spatially enabled with postgis,this was tested before with the classic java app.

I extented my model class for todo tasks as follows:

package models;

import java.util.*;

import play.db.ebean.*;
import play.data.validation.Constraints.*;

import javax.persistence.*;

import com.vividsolutions.jts.geom.Point;
import org.hibernate.annotations.Type;

@Entity
public class Task extends Model {

@Id
public Long id;

@Required
public String label;

@Type(type="org.hibernate.spatial.GeometryType")
@Column(columnDefinition="Point") 
public Point location;

public static Finder<Long,Task> find = new Finder(Long.class, Task.class);

public static List<Task> all() {
    return find.all();
}

public static void create(Task task) {
    task.save();
}

public static void delete(Long id) {
    find.ref(id).delete();  
}
}

Also I added Postgis JPA Dialect to my conf file:

jpa.dialect=org.hibernate.spatial.dialect.postgis.PostgisDialect

Play compiles everything fine, there where some errors, when libraries where missing in the classpath, but I added one and another as listed above until no error appeared anymore. Nevertheless no database evolution for the new location field was triggered. It seems like play is ignoring all hibernate-spatial specific parts of my app. It is working the same way as the normal todolist app before.

I think it has something to do with different hibernate versions (is play using hibernate3 or hibernate4? Can I upgrade to 4?). Can somebody, who already is experienced with this, tell me which versions of each library he used and which config settings had to be done?

UPDATE: As Christopher mentioned, I mixed up ebean and jpa. So I took the jpa-sample and transfered it onto my simple todolist sample. I updated play project files and dependencies, rewired model and controller to fit to the JPA EntityManager and removed some libraries from the classpath so that I am using hibernate 3 which is on board of play 2.1. I also did configuration nearly like it is in the jpa example, my persistence.xml and application.conf nearly look like the same, except that I am using postgres dialect for hibernate. I can compile my project, but when I start it, I get

PersistenceException: [PersistenceUnit: defaultPersistenceUnit] Unable to configure EntityManagerFactory

I configured play's verbosity to debug, so I found out, that this exception comes up after PropertyBinder builds the id property of my Task Entity.

Think I come some steps further, but no end in sight...

Was it helpful?

Solution

You appear to be mixing in Ebean with JPA - they are mutually exclusive.

Here is a JPA example for you:

https://github.com/playframework/Play20/tree/master/samples/java/computer-database-jpa

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top