Thanks everyone for your comments.
As it turns out, the main issue for me was that my database
configurations for running play in "test" mode (i.e. "sudo play test")
were all set to the defaults (db=mem etc.)
Once I created these configurations...
%test.application.mode=dev
%test.db.url=jdbc:postgresql://localhost/octopus
%test.db.driver=org.postgresql.Driver
%test.db.user=andrew
%test.db.pass=**********
%test.db.default.schema=public
%test.jpa.ddl=create-drop
%test.jpa.dialect=org.hibernate.dialect.PostgreSQLDialect
Then JPA actually drops/creates the tables and I can extend my model
classes from play.db.jpa.Model and save() now works.
The tables which Hibernate generates are fine, but as Alexander
mentioned, a single sequence called hibernate_sequence is created and
used as the source for *all* id's - not really ideal since each table
could have its own id space. Neither are the default settings for
@SequenceGenerator which use allocationSize=50, so your id goes from
1 .. 51 .. 101 .. clearly this is not meant for identity-like
autogenerated primary keys.
I am still not out of the woods. I'm plagued with bizarre errors,
such as these:
Query query = JPA.em().createQuery("select * from WebUser"); /* <--
Fails with: "org.hibernate.hql.ast.QuerySyntaxException: unexpected
token: * near line 1, column 8 [select * from public.WebUser]" */
List<WebUser> founds = WebUser.findAll(); /* <-- Fails with: "A
java.lang.NoSuchFieldError has been caught, NONE" */
WebUser found = WebUser.findById(1L); /* Works for some reason... :/
*/
On Nov 29, 11:59 pm, Alexander Strebkov <
alexanderstreb...@gmail.com>
wrote:
> I'm also using postgresql with play framework and I also had to solve
> some problems with sequences. Will share my experience - maybe it will
> help you.
>
> I think your problem is you do not have a sequence defined in postgres
> which Hibernate expects you to have. If you enable jpa.ddl=update in
> application.conf - Hibernate will create/update database schema for
> you and it will create one postgres sequence to use to get a "next
> value" for id fields of ALL tables. So by default you will never get
> records with the same id in any table in your database. You can try to
> enable jpa.ddl=update with empty database and see a schema Hibernate
> will create for you (and Hibernate will expect your scheme to be
> compatible with it, including sequence). You also do not need to use
> bigserial - just bigint, because Hibernate will use sequences
> "manually" anyway.
>
> I didn't enjoyed this "one sequence per database" Hibernate's default
> so I found custom dialect which make it "one sequence per table":
http://grails.1312388.n4.nabble.com/One-hibernate-sequence-is-used-fo...