问题描述
我正在玩 computer-database-jpa (Java) Play Framework 2.1 示例应用程序.当我在内存数据库中使用 H2 时一切正常,但是当我想将应用程序与 MySQL 连接时遇到问题.
I'm playing with computer-database-jpa (Java) Play Framework 2.1 sample application. Everything works fine when I'm using H2 in memory database but I had problems when I want to connect the application with MySQL.
有些人遇到了同样的问题(帮助希望将示例应用程序连接到MySQL) 但没有解决方案.
Some one had the same problem (Help wanted getting sample app connected to MySQL) but there was no solution.
我添加了 mysql-connector
(Build.scala):
I've added mysql-connector
(Build.scala):
val appDependencies = Seq(
....
"mysql" % "mysql-connector-java" % "5.1.18"
)
并编辑application.conf:
and edited application.conf:
db.default.url="jdbc:mysql://password:user@localhost/my-database"
db.default.driver=com.mysql.jdbc.Driver
当我启动应用程序并应用 1.sql(进化脚本)时,出现错误:
When I start the applications and apply 1.sql (evolution script) I get an error:
You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'sequence company_seq
start with 1000' at line 1 [ERROR:1064, SQLSTATE:42000]
有人知道如何解决这个问题吗?
Does anyone have an idea how to solve the problem?
推荐答案
我找到了解决方案 - https://github/opensas/openshift-play2-computerdb.
I've found the solution - https://github/opensas/openshift-play2-computerdb.
进化脚本中使用的语法不符合MySQL
:
Syntax used in evolution scripts isn't conform with MySQL
:
因为我玩的是 Java
而不是 Scala
版本,所以我要更改 Company.java
和 Computer.java
文件.我添加了 @GeneratedValue
注释:
Because I was playing with Java
and not Scala
version I'd to change Company.java
and Computer.java
files. I've added @GeneratedValue
annotation:
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Long id;
在这里你可以找到修改后的进化脚本:https://github/opensas/openshift-play2-computerdb/tree/master/conf/evolutions/default
Here you can find modified evolution scripts: https://github/opensas/openshift-play2-computerdb/tree/master/conf/evolutions/default
这篇关于连接“计算机-数据库-jpa"使用 MySQL 播放 2.1 示例应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论