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
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:
- How to play video Using Url On Android?Best solution by Stack Overflow
- How to create a Restful web service in .Net Using MySQL?Best solution by stackoverflow.com
- How to load native library to play framework?Best solution by Stack Overflow
- How to store an image in database using MySQL?Best solution by stackoverflow.com
- how to play video using mediaElement in wpf?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.