Getting my head around hibernate & play

104 views
Skip to first unread message

henry.oswald

unread,
Mar 20, 2011, 10:27:36 AM3/20/11
to play-framework
I'm trying to get my head around hibernate,

I built the tutorial Yabe blog, that works fine. Then messing around I
added another model called task. Then I created an instance of task,
and tried to .save() it. I assumed that a new table would be created
called task and it would all work but this isn't the case, no new
table just errors saying it couldn't insert. Doesn't hibernate take
care of this?

Thanks for the advice.

Alexander Reelsen

unread,
Mar 20, 2011, 11:41:30 AM3/20/11
to play-fr...@googlegroups.com
Hi Henry

henry.oswald wrote:
> I built the tutorial Yabe blog, that works fine. Then messing around I
> added another model called task. Then I created an instance of task,
> and tried to .save() it. I assumed that a new table would be created
> called task and it would all work but this isn't the case, no new
> table just errors saying it couldn't insert. Doesn't hibernate take
> care of this?

It should.

Have you added an @Entity annotation to the Task class definition? When
you called save() you surely already extended Task from model like this:

@Entity
public class Task extends Model {
...
}

If you did so, did anything occur up in the logs? Could you paste it here?


--Alexander

henry.oswald

unread,
Mar 20, 2011, 12:23:29 PM3/20/11
to play-framework
Hmmm, strange. To create the Task model I duplicated one of the other
models, cleared its attributes and methods out and changed the names.

Here is the error:

PersistenceException occured :
org.hibernate.exception.SQLGrammarException: could not insert:
[models.Task]

play.exceptions.JavaExecutionException:
org.hibernate.exception.SQLGrammarException: could not insert:
[models.Task]
at play.jobs.Job.call(Job.java:119)
at Invocation.Job(Play!)
Caused by: javax.persistence.PersistenceException:
org.hibernate.exception.SQLGrammarException: could not insert:
[models.Task]
at
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:
1235)
at
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:
1168)
at
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:
1174)
at
org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:
674)
at play.db.jpa.JPABase._save(JPABase.java:37)
at play.db.jpa.GenericModel.save(GenericModel.java:187)
at Bootstrap.doJob(Bootstrap.java:15)
at play.jobs.Job.doJobWithResult(Job.java:37)
at play.jobs.Job.call(Job.java:110)
... 1 more

Here is the class file:

package models;
import java.util.*;
import javax.persistence.*;
import play.db.jpa.*;
import play.data.validation.*;

@Entity
public class Task extends Model {

public String name;

public Task(String name) {
this.name = name;
}
}

Werner Vesterås

unread,
Mar 20, 2011, 5:25:57 PM3/20/11
to play-framework
Could you please post the application.conf file for your project?

Werner
Oslo, Norway

henry.oswald

unread,
Mar 20, 2011, 7:34:08 PM3/20/11
to play-framework
Thanks guys, here is my config:
BTW The JDBC configerations are for an EC2 I was messing around with
(which worked fine).

# This is the main configuration file for the application.
# ~~~~~
application.name=HenrysBlog

# Application mode
# ~~~~~
# Set to dev to enable instant reloading and other development help.
# Otherwise set to prod.
#application.mode=dev
application.mode=prod

# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions
# If you deploy your application to several instances be sure to use
the same key !
application.secret=PjaunvWIRSAcsGy7pKXMQGBYBHVMPPszYIDoJ8rXMkbj7rwdO4sn8AKWkgnJ54mV

# Additional modules
# ~~~~~
# A module is another play! application. Add a line for each module
you want
# to add to your application. Modules path are either absolutes or
relative to
# the application root.
# They get loaded from top to bottom; Syntax: module.{name}={path}
#
# Keep the next line as is to help the play script to manage modules.
# ---- MODULES ----


# i18n
# ~~~~~
# Define locales used by your application.
# You can then place localized messages in conf/messages.{locale}
files
# application.langs=fr,en,ja

# Date format
# ~~~~~
#date.format=yyyy-MM-dd
date.format.fr=dd-MM-yyyy

# Server configuration
# ~~~~~
# If you need to change the HTTP port, uncomment this (default is set
to 9000)
#http.port=80
#
# By default the server listen for HTTP on the wilcard address.
# You can restrict this.
# http.address=127.0.0.1

# Session configuration
# ~~~~~~~~~~~~~~~~~~~~~~
# By default, session will be written to the transient PLAY_SESSION
cookie.
# The cookies are not secured by default, only set it to true
# if you're serving your pages through https.
# application.session.cookie=PLAY
# application.session.maxAge=1h
# application.session.secure=false

# Import the secure module
module.secure=${play.path}/modules/secure

# JVM configuration
# ~~~~~
# Define which port is used by JPDA when application is in debug mode
(default is set to 8000)
# jpda.port=8000
#
# Java source level => 1.5, 1.6 or 1.7 (experimental)
# java.source=1.5

# Log level
# ~~~~~
# Specify log level for your application.
# If you want a very customized log, create a log4j.properties file in
the conf directory
# application.log=INFO
#
# More logging configuration
# application.log.path=/log4j.properties
# application.log.system.out=off

# Database configuration
# ~~~~~

# Import the crud module
module.crud=${play.path}/modules/crud

# Enable a database engine if needed.
#
# To quickly set up a development database, use either:
# - mem : for a transient in memory database (HSQL in memory)
# - fs : for a simple file written database (HSQL file stored)
# db=mem
#
#To connect to a local MySQL5 database, use:
db=mysql:henry:pass@blog
#
# If you need a full JDBC configuration use the following :
#db.url=jdbc:mysql://46.137.107.79:3306/blog
#db.driver=com.mysql.jdbc.Driver
#db.user=henry
#db.pass=tuborg123
#
# Connections pool configuration :
# db.pool.timeout=1000
# db.pool.maxSize=30
# db.pool.minSize=10
#
# If you want to reuse an existing Datasource from your application
server, use:
# db=java:/comp/env/jdbc/myDatasource

# JPA Configuration (Hibernate)
# ~~~~~
#
# Specify the custom JPA dialect to use here (default to guess):
# jpa.dialect=org.hibernate.dialect.PostgreSQLDialect
#
# Specify the ddl generation pattern to use. Set to none to disable
it
# (default to update in DEV mode, and none in PROD mode):
# jpa.ddl=update
#
# Debug SQL statements (logged using DEBUG level):
# jpa.debugSQL=true
#
# You can even specify additional hibernate properties here:
# hibernate.use_sql_comments=true
# ...
#
# Store path for Blob content
attachments.path=data/attachments

# Memcached configuration
# ~~~~~
# Enable memcached if needed. Otherwise a local cache is used.
# memcached=enabled
#
# Specify memcached host (default to 127.0.0.1:11211)
# memcached.host=127.0.0.1:11211
#
# Or you can specify multiple host to build a distributed cache
# memcached.1.host=127.0.0.1:11211
# memcached.2.host=127.0.0.1:11212

# HTTP Response headers control for static files
# ~~~~~
# Set the default max-age, telling the user's browser how long it
should cache the page.
# Default is 3600 (one hour). Set it to 0 to send no-cache.
# This is only read in prod mode, in dev mode the cache is disabled.
# http.cacheControl=3600

# If enabled, Play will generate entity tags automatically and send a
304 when needed.
# Default is true, set it to false to deactivate use of entity tags.
# http.useETag=true

# Custom mime types
# mimetype.xpi=application/x-xpinstall

# WS configuration
# ~~~~~
# If you need to set proxy params for WS requests
# http.proxyHost = localhost
# http.proxyPort = 3128
# http.proxyUser = jojo
# http.proxyPassword = jojo

# Mail configuration
# ~~~~~
# Default is to use a mock Mailer
#mail.smtp=mock

# Or, specify mail host configuration
# mail.smtp.host=127.0.0.1
# mail.smtp.user=admin
# mail.smtp.pass=
# mail.smtp.channel=ssl

# Jobs executor
# ~~~~~~
# Size of the Jobs pool
# play.jobs.pool=10

# Execution pool
# ~~~~~
# Default to 1 thread in DEV mode or (nb processors + 1) threads in
PROD mode.
# Try to keep a low as possible. 1 thread will serialize all requests
(very useful for debugging purpose)
# play.pool=3

# Open file from errors pages
# ~~~~~
# If your text editor supports opening files by URL, Play! will
# dynamically link error pages to files
#
# Example, for textmate:
# play.editor=txmt://open?url=file://%s&line=%s

# Testing. Set up a custom configuration for test mode
# ~~~~~
#%test.module.cobertura=${play.path}/modules/cobertura
#%test.application.mode=dev
#%test.db=mem
#%test.jpa.ddl=create-drop
#%test.mail.smtp=mock

module.stax=${play.path}/modules/stax-1.0
module.pdf=${play.path}/modules/pdf-0.2
module.playapps=${play.path}/modules/playapps-1.3

#play apps configeration
%playapps.application.mode=prod
%playapps.application.log=INFO
%playapps.db=mysql:play:play@play
%playapps.http.port=9000
%playapps.jpa.ddl=update

blog.title=Title should be here
blog.baseline=this is the baseline

henry.oswald

unread,
Mar 20, 2011, 7:47:44 PM3/20/11
to play-framework
GAH! So I had the application set in prod -> no db changes. These
little things have a habit of catching me out when I learn a new
system!

Thanks for your help guys. It is appreciated and noted! An active
community is important for me.

Ike

unread,
Mar 21, 2011, 8:17:19 AM3/21/11
to play-fr...@googlegroups.com
You may want to consider changing your application secret and your db password now. It's generally a good idea to scrub your files for sensitive data before posting them online.
Reply all
Reply to author
Forward
0 new messages