How to hybrid Mysql and MongoDB in Play framework?

Play! Framework - Using MySQL and MongoDB for same application

  • Is it possible to user MySQL Database and MongoDb database for same project using Play! framework? for example: I want @Entity Person to interact with my MySQL database and @Entity PersonData to interact with my MongoDB database? How can I do that? Please let me know Thank you

  • Answer:

    Yes, it is possible. Just use the Morphia plugin for Play. I have done it before. It is quite simple. For the MongoDB models, just do something like this: import play.modules.morphia.Model; @Entity public class YourMongoModel extends Model { ... } For the MySQL model, do this: import play.db.jpa.Model; @Entity public class LogMessageX extends Model { ... } Notice the different imports. Then the application.conf file should contains something like this: # For MongoDB morphia.db.host=localhost morphia.db.port=27017 morphia.db.name=YourMongoDBName # for MySQL db=mysql:user:pwd@database_name

daydreamer at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

On the MySQL entity extend Model and add the JPA annotation (@Entity). For Mongo you need to use a third-party module such as this one: http://www.playframework.org/modules/mongo-1.3/home Example: @MongoEntity("collectionName") public class Car extends MongoModel { public String name; public String colour; public int topSpeed; } Play's JPA plugin will not modify the Mongo class since it won't have the JPA @Entity annotation. For anyone out there interested, checkout Play's JPAEnhancer. It uses javaassist to modify the bytecode and add all the method impls - very cool!

Felipe Oliveira

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.