I am able to connect to my default database. But added to that I also want to connect another database. I am using Play Framework 1.2.6. I know that this support is present in the main branch of Play 1.2.x. Can any one please help me, how I can achieve this in 1.2.6.
Thank you
Play 1.2.6 (or the 1.2.x branch) doesn't support multiple database connections out of the box.
This support will be available in Play 1.3 which has not been released yet.
Here is the according ticket from the Play bug tracker:
http://play.lighthouseapp.com/projects/57987-play-framework/tickets/706
What database are you using? If your database supports multiple schemas you can achieve what you want by adding the following line on top of class.
#Entity
#Table(name="<table_name>",schema="<schema_2>")
public class xxx extends Model {
Entity and Table are part of the persistence api.
Found another interesting solution to your problem. Use below link if you need occasional access to the second database.
click here
You can try to use this module : http://www.playframework.com/modules/multidb
Aj.
Related
I have created some mysql databases in mysql.
Now I am trying to get them into my web application by using the play framework.
I added the mysql configs in the application.conf, added the dependency for the mysql driver in the build.sbt, created my first model and added the models packages as the ebean default in the application.conf.
Now when I go into my browser I get this error:
I`m a little confused right now, because I do not want to create a new table, but use the one I created already.
Any idea what I am doing wrong??
Play's default behaviour during development is to manage your database via the evolutions plugin. You define your initial schema in conf/evolutions/default/1.sql and then apply subsequent modifications in 2.sql, 3.sql etc etc. Whenever there are changes to these evolution files the plugin will attempt to run these on the database, which is what you're seeing here (although it looks like an error, it's really just trying to be helpful.)
If you want to manage the schema yourself (and you probably should on a production DB, for example) add evolutionplugin=disabled to the application.conf file.
I'm trying to connect to cassandra database using spring data (preferably jpa). I can not find any clera example how to do it, no guide. I found some for MongoDB and Neo4j, but none for cassandra. On mail page of spring there is a mention of coassandra project but none exmaple or guide is provided. Can any one help?
Which version of spring-data-cassandra are you using?
v.1 https://github.com/spring-projects/spring-data-cassandra v.
v.2 https://github.com/SpringData/spring-data-cassandra
For v.1 see http://docs.spring.io/spring-data/cassandra/docs/1.1.0.RC1/reference/html/#cassandra-connectors
I'm using v.2 and also had problems with finding tutorials/examples. But there are test inside the lib itself. See eg. spring-data-cassandra/cassandra/src/test/resources/org/springdata/cassandra/test/integration/config/XmlConfigTest-context.xml - you need to change only few things to make it work with your DB. When cofig is ready you can use CqlOperations to run your queries:
#Autowired
private CqlOperations cassandraTemplate;
cassandraTemplate.buildSaveNewOperation(new Foo("bar")).execute();
And that's basically it :)
I used spring-data-cassandra-1.1.2.RELEASE. Here are 2 links which provide you detailed steps to configure Cassandra with Spring Data: link1 and link2.
I followed the XML configuration way mentioned in link2, but faced one problem. I guess the ticket for this problem is here and is still open. This problem was resolved by just removing the id attribute from <cassandra:template id="cassandraTemplate" />. This code is from the config xml shown in the section 4.3.2 of link2.
Apart from this I did not face any problems and the Spring data Cassandra integration worked fine.
Section 5.1 from this link can also be used.
I use JPA with EclipseLink in my Java project. In the first version of my project I have a couple of entity classes and a little program logic. This version has now been in use for a bit of time and data has been inserted by the users.
Now I have a newer version of my project where I have more entities in total and old entities have changed or partially have been replaced by others.
My question now is how to update between my first and my second version (client side) without loosing the data from the first version. I know there is the possiblity to preload a load.sql, but then my project depends on one database. My clients use both MySQL and Oracle as database.
How would I do the update? Is there any way to use JPA for it?
Thanks to #JBNizet for the answer. The result is to either use higher level libraries like Liquibase or Flyway, or to create SQL scripts and test them before execution.
I have a JDBC application that uses Apache Derby. How can I migrate my entire database system to use MySQL?
I have 3 Java programs that access the database
I have 3 tables and 2 views
I am using Netbeans. I have never used MySQL before and do not know where to begin. Is there nice integration with Java and MySQL in Netbeans? How can I get nice integration with NetBeans and MySQL?
All help is greatly appreciated!
Looks like this plugin would probably help you:
http://netbeans.org/kb/docs/ide/mysql.html
I found this tutorial on the Spring site, but I think it is only a partial solution.
Tutorial
In it they are relying on hibernate to drop and create the tables, and I really don't like that. You have to go through special coding to add static data. For example, if your app is tracking devices, you probably want a table of device_types. At least some o those device types will be in the db, as well as devices, users, etc.
What I intend to do, is to use Derby until I am somewhat stable. From it, I will get the database schema and create it in mysql. It seems that the DB look utility can be used for that. DB Look
As added security I intend to run my web app with a db user that does not have the ability to add or drop tables. Also it is possible to remove the permission to delete rows if you use the concept of making rows "inactive" So instead of deleting a no longer used device type, you set the "active" flag to F. So your device type query would look like:
select * from device_type where active = 'T'
I want to implement a sample in java that reads a configuration from some config file and, based on that, when user interacts with the page the application will store some data on either MySql or Oracle according to the configuration parameters. How can we implement this sample in most efficient and smart way?
Indeed using Hibernate or JPA allows you to abstract the database differences away.
With a dependency injection framework like Spring or Guice you can then create 2 service instances which differ only in the persistence manager which is injected.
In this case you can keep almost 100% of the code identical for the 2 databases which guarantees they will not get out of sync over time.
Make an interface for data storage, and use that in your application
Make an abstract class which implements this interface and implements the functionality which MySQL and Oracle have in common.
Make two classes, one for MySQL and one for Oracle which implement the database-specific stuff.
In your configuration, specifiy which class to use (MySQL or Oracle database class).
Maybe use something like Hibernate, which abstracts the database away from you.
Following up on #Sjoerd's answer:
Any tools or open source libs that can be helpful?
Hibernate or some other JPA implementation is your best bet.
Alternatively, Spring has some JDBC support classes that do some of the work ... if you can figure out which of the various alternatives is a good match to your requirements.
Unfortunately, implementing an application that works against multiple database backends is hard work, no matter how you do it. In my experience, you usually end up with a solution that doesn't perform as well as a solution that is tailored to one and only one database back end.
If I had my way, database vendors who refuse to implement the SQL standard would be first against the wall ... come the revolution.