Play Framework + Oracle = EASY!

To configure your oracle database using the play framework you need to follow the following steps:

  1. Choose the JAR with the drivers according to your oracle’s database version and put in the lib/ directory of your web application
  2. Configure your application.conf file,  located inside the conf/ directory
    • In the JPA Configuration Section you have to choose the JPA (Hibernate) dialect. In my case I was working with oracle10g so i had to insert in the configuration file:
      • jpa.dialect=org.hibernate.dialect.Oracle10gDialect
    • Now you just need to add the following lines, according to your database (including username and password).
      • db.url=jdbc:oracle:thin:@yourdatabaseserver:1521:dbname
        db.driver=oracle.jdbc.driver.OracleDriver
        db.user=yourusername
        db.pass=yourpassword
  3. Now you just need to restart the server. He adds the database drivers automatically to the classpath of the project.
  4. If you want, you can generate Netbeans or Eclipse projects, so you can open this projects with everything configured.

Really easy with no XMLs!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • FriendFeed
  • LinkedIn
  • MySpace
  • Twitter
This entry was posted in Internet, play, Software Development and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

9 Comments

  1. Pedro Mendes
    Posted October 2, 2011 at 10:55 | Permalink

    Hi Hugo,

    Thanks for this useful post!

    I’m facing some problems connecting my oracle db using this configuration. It seems the default H2 db is always used even the “db=mem” is comment out.

    I’m getting the following output when accessing my Play!’s app


    0:43:12,923 INFO ~ Listening for HTTP on port 9000 (Waiting a first request to start) …
    10:43:33,368 INFO ~ Connected to jdbc:h2:mem:play;MODE=MYSQL;LOCK_MODE=0
    10:43:35,589 INFO ~ Application ‘snet’ is now started !

    I think I should be seen some like “Connected tojdbc:oracle:thin:@:1521:”, right?

    In my application.conf, in the lines regarding the Database and JPA configuration, I havee:

    # Database configuration

    # db=mem
    db.url=jdbc:oracle:thin:@:1521:
    db.driver=oracle.jdbc.driver.OracleDriver
    db.user=cadrede
    db.pass=admdev

    # JPA Configuration (Hibernate)
    jpa.dialect=org.hibernate.dialect.Oracle10gDialect

    What am I missing out?

    Thanks, in advance!

  2. Posted October 2, 2011 at 11:37 | Permalink

    Hmmm, it should have worked.

    Let’s try to create another configuration. On my projects, I use in-memory database when my framework id is dev.
    This is good for testing experimental features where the structure of the database is changed.
    Let’s create a configuration “test”:

    # Database configuration
    %test.db.url=jdbc:oracle:thin:@:1521:
    %test.db.driver=oracle.jdbc.driver.OracleDriver
    %test.db.user=cadrede
    db.pass=admdev

    # JPA Configuration (Hibernate)
    %test.jpa.dialect=org.hibernate.dialect.Oracle10gDialect

    I just added “%test” in all of your configurations :-)

    Now, when you start the play server just do the command: “play run snet –%test”
    My goal with creating another id is to create a clean configuration of another environment to see if everything is well configured.

    If you want to more about the framework ids, just visit: http://www.playframework.org/documentation/1.2/ids

  3. Pedro Mendes
    Posted October 2, 2011 at 12:12 | Permalink

    Hi Hugo,

    Thanks for the fast reply! Immediately after I submitted my doubt to you, I had a second look at my app conf and I spotted the bottom of the file the in-memory db declared for testing purposes.. I forgot to mention that I was testing the connection to the oracle db through the app’s Test Runner.. so the use of the in-memory db made sense!

    I can know connect successfully to my oracle db! :)

    Thanks for the tips anyway and it would be really nice that you continue to post here your experiences with Play! Framework! _filipera (Filipe Oliveira) explained once why he was in love with Play!… I understand know!

    Well, I must continue my “fight” with Play! + Hibernate + Oracle, but now adding a variation to it: Hibernate Spatial… The HBSpatial’s ConnectionFinder needs the OracleConnection from the current Connection but it’s not getting it… Already tried several versions of the Oracle JDBC driver, but with no luck.

    Any thoughts about this? =)

    Stay fit & well!

    By the way

  4. Posted October 2, 2011 at 12:39 | Permalink

    Hello Pedro,

    I have never used Hibernate-Spatial, there are a few posts in play! google groups: about it. Just give it a quick read :-)

    You have to take into account that play! uses a forked version of hibernate.

    Good luck and thanks!

  5. Pedro Mendes
    Posted October 2, 2011 at 14:01 | Permalink

    “You have to take into account that play! uses a forked version of hibernate.”

    Well putted.. Thanks Hugo!

  6. Posted November 6, 2011 at 03:03 | Permalink

    Hello, I’m tryng connect Play! with Oracle 11g … i’m used the jdbc driver ojdbc6dms.jar and these are conection parameters in application.conf:

    # If you need a full JDBC configuration use the following :
    db.url=jdbc:oracle:thin@//localhost:1521:mybd
    db.driver=oracle.jdbc.driver.OracleDriver
    db.user=myusername
    db.pass=mypassword

    # Specify the custom JPA dialect to use here (default to guess):
    jpa.dialect=org.hibernate.dialect.OracleDialect

    But, show me this error:

    Database error
    A database error occured : Cannot connected to the database, La dirección URL de Oracle especificada no es válida

  7. Posted November 6, 2011 at 03:09 | Permalink

    Remove the // on the localhost word. It should work.

  8. Posted November 6, 2011 at 10:43 | Permalink

    I can’t resolved … Uhmmm, should not set something in the dependencies.yml ?? is correct, the driver I’m using?
    Thanks!

  9. Posted November 14, 2011 at 16:32 | Permalink

    Did you created the mybd db?

    Changed the configuration:

    # If you need a full JDBC configuration use the following :
    db.url=jdbc:oracle:thin@//localhost:1521:mybd
    db.url=jdbc:oracle:thin@localhost:1521:mybd
    db.driver=oracle.jdbc.driver.OracleDriver
    db.user=myusername
    db.pass=mypassword

    # Specify the custom JPA dialect to use here (default to guess):
    jpa.dialect=org.hibernate.dialect.OracleDialect

    Let me know if you solve it.
    Thanks.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>