Heroku上的@Id和@GeneratedValue失败

时间:2014-09-07 15:37:29

标签: hibernate postgresql heroku playframework ebean

尝试部署我的游戏时! 2.2.2应用程序到heroku,它失败了。我从heroku logs

中提取了此错误
2014-09-07T15:33:56.237313+00:00 app[web.1]: play.api.Application$$anon$1: Execution exception[[PersistenceException: Error getting sequence nextval]]
2014-09-07T15:33:56.225226+00:00 app[web.1]: [error] play - Cannot invoke the action, eventually got an error: javax.persistence.PersistenceException: Error getting sequence nextval
2014-09-07T15:33:56.237314+00:00 app[web.1]:    at play.api.Application$class.handleError(Application.scala:293) ~[com.typesafe.play.play_2.10-2.2.3.jar:2.2.3]
2014-09-07T15:33:56.237335+00:00 app[web.1]: Caused by: org.postgresql.util.PSQLException: ERROR: relation "problems_seq" does not exist
2014-09-07T15:33:56.237330+00:00 app[web.1]:    at com.avaje.ebeaninternal.server.deploy.BeanDescriptor.nextId(BeanDescriptor.java:1133) ~[org.avaje.ebeanorm.avaje-ebeanorm-3.2.2.jar:na]
2014-09-07T15:33:56.237302+00:00 app[web.1]: [error] application -
2014-09-07T15:33:56.237326+00:00 app[web.1]:    at com.avaje.ebean.config.dbplatform.SequenceIdGenerator.getMoreIds(SequenceIdGenerator.java:211) ~[org.avaje.ebeanorm.avaje-ebeanorm-3.2.2.jar:na]
2014-09-07T15:33:56.237336+00:00 app[web.1]:   Position: 16
2014-09-07T15:33:56.237339+00:00 app[web.1]:    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1836) ~[postgresql.postgresql-9.1-901-1.jdbc4.jar:na]
2014-09-07T15:33:56.237344+00:00 app[web.1]:    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:273) ~[postgresql.postgresql-9.1-901-1.jdbc4.jar:na]
2014-09-07T15:33:56.237321+00:00 app[web.1]:    at scala.Option.map(Option.scala:145) [org.scala-lang.scala-library-2.10.3.jar:na]
2014-09-07T15:33:56.237324+00:00 app[web.1]: Caused by: javax.persistence.PersistenceException: Error getting sequence nextval
2014-09-07T15:33:56.237338+00:00 app[web.1]:    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103) ~[postgresql.postgresql-9.1-901-1.jdbc4.jar:na]
2014-09-07T15:33:56.237343+00:00 app[web.1]:    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388) ~[postgresql.postgresql-9.1-901-1.jdbc4.jar:na]
2014-09-07T15:33:56.237323+00:00 app[web.1]:    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3.applyOrElse(PlayDefaultUpstreamHandler.scala:264) [com.typesafe.play.play_2.10-2.2.3.jar:2.2.3]
2014-09-07T15:33:56.237308+00:00 app[web.1]:
2014-09-07T15:33:56.237319+00:00 app[web.1]:    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:264) [com.typesafe.play.play_2.10-2.2.3.jar:2.2.3]
2014-09-07T15:33:56.237327+00:00 app[web.1]:    at com.avaje.ebean.config.dbplatform.SequenceIdGenerator.loadMoreIds(SequenceIdGenerator.java:161) ~[org.avaje.ebeanorm.avaje-ebeanorm-3.2.2.jar:na]
2014-09-07T15:33:56.237332+00:00 app[web.1]:    at com.avaje.ebeaninternal.server.persist.DefaultPersister.setIdGenValue(DefaultPersister.java:1239) ~[org.avaje.ebeanorm.avaje-ebeanorm-3.2.2.jar:na]
2014-09-07T15:33:56.237341+00:00 app[web.1]:    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:512) ~[postgresql.postgresql-9.1-901-1.jdbc4.jar:na]
2014-09-07T15:33:56.237310+00:00 app[web.1]: ! @6jehmmg85 - Internal server error, for (GET) [/] ->
2014-09-07T15:33:56.237316+00:00 app[web.1]:    at play.api.DefaultApplication.handleError(Application.scala:399) [com.typesafe.play.play_2.10-2.2.3.jar:2.2.3]
2014-09-07T15:33:56.237328+00:00 app[web.1]:    at com.avaje.ebean.config.dbplatform.SequenceIdGenerator.nextId(SequenceIdGenerator.java:118) ~[org.avaje.ebeanorm.avaje-ebeanorm-3.2.2.jar:na]
2014-09-07T15:33:56.237340+00:00 app[web.1]:    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257) ~[postgresql.postgresql-9.1-901-1.jdbc4.jar:na]
2014-09-07T15:33:56.237318+00:00 app[web.1]:    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:264) [com.typesafe.play.play_2.10-2.2.3.jar:2.2.3]
2014-09-07T15:33:56.237334+00:00 app[web.1]:    at com.avaje.ebeaninternal.server.persist.DefaultPersister.insert(DefaultPersister.java:334) ~[org.avaje.ebeanorm.avaje-ebeanorm-3.2.2.jar:na]

具体来说,这一行Caused by: org.postgresql.util.PSQLException: ERROR: relation "problems_seq" does not exist似乎是个问题。

我的模特看起来像这样:

@Entity
@Table(name = "problems")
public class Problem extends Model {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "problems_id_seq")
    @SequenceGenerator(name = "problems_id_seq", sequenceName = "problems_id_seq", allocationSize = 1)
    @Column(name = "problem_id")
    public Long id;

    // other properties
}

我想知道为什么这会因为序列错误而失败,即使我想使用GenerationType.IDENTITY?底层数据库是postgres。

2 个答案:

答案 0 :(得分:1)

我可以通过切换到Postgres数据库进行本地开发来解决此问题。另外我发现由于全局.gitignore设置,进化文件没有签入Heroku。

答案 1 :(得分:0)

我认为这会有所帮助

@Entity
@Table(name = "problems")
public class Problem extends Model {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "problems_id_seq")
    @SequenceGenerator(name = "problems_id_seq", sequenceName = "problems_id_seq", allocationSize = 1)
    @Column(name = "problem_id")
    public Long id;

    // other properties
}