我正在尝试将我的表单插入到h2数据库中。 我正在使用hibernate和jpa。这是代码
package models;
import java.util.*;
import javax.persistence.*;
import play.data.format.*;
import play.data.validation.*;
import play.db.jpa.*;
@Entity
public class MedicalIncident {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public int id;
@Constraints.Required
public String month;
@Constraints.Required
public String place;
@Constraints.Required
public String unit;
@Constraints.Required
public String incident_type;
@Constraints.Required
public int age;
/**
* Insert this new incident submission.
*/
@Transactional
public void toDataBase() {
// persist object - add to entity manager
JPA.em().merge(this);
JPA.em().persist(this);
}
}
我正面临着一个问题。这是一个错误:
[PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement]
它看起来像使用ebean而不是jpa / hibernate。我是来自堆栈跟踪的客人:
[info] play - datasource [jdbc:h2:mem:SupraCIRS] bound to JNDI as DefaultDS
[info] play - database [default] connected at jdbc:h2:mem:SupraCIRS
[info] play - Application started (Dev)
[error] o.h.e.j.s.SqlExceptionHelper - Kolumna "MEDICALINC0_._EBEAN_INTERCEPT" nie istnieje
Column "MEDICALINC0_._EBEAN_INTERCEPT" not found; SQL statement:
select medicalinc0_.id as id1_0_0_, medicalinc0_._ebean_intercept as _ebean_i2_0_0_, medicalinc0_.age as age3_0_0_, medicalinc0_.incident_type as incident4_0_0_, medicalinc0_.month as month5_0_0_, medicalinc0_.place as place6_0_0_, medicalinc0_.unit as unit7_0_0_ from MedicalIncident medicalinc0_ where medicalinc0_.id=? [42122-172]
[error] play - Cannot invoke the action, eventually got an error: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement
[error] application -
! @6ghh1j2nn - Internal server error, for (POST) [/incydent_medyczny/zapisz] ->
play.api.Application$$anon$1: Execution exception[[PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement]]
at play.api.Application$class.handleError(Application.scala:293) ~[play_2.10.jar:2.2.1]
at play.api.DefaultApplication.handleError(Application.scala:399) [play_2.10.jar:2.2.1]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:261) [play_2.10.jar:2.2.1]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:261) [play_2.10.jar:2.2.1]
at scala.Option.map(Option.scala:145) [scala-library.jar:na]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2.applyOrElse(PlayDefaultUpstreamHandler.scala:261) [play_2.10.jar:2.2.1]
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387) ~[hibernate-entitymanager-4.2.6.Final.jar:4.2.6.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310) ~[hibernate-entitymanager-4.2.6.Final.jar:4.2.6.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1316) ~[hibernate-entitymanager-4.2.6.Final.jar:4.2.6.Final]
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:898) ~[hibernate-entitymanager-4.2.6.Final.jar:4.2.6.Final]
at models.MedicalIncident.toDataBase(MedicalIncident.java:40) ~[na:na]
at controllers.MedicalIncidents.submit(MedicalIncidents.java:50) ~[na:na]
Caused by: org.hibernate.exception.SQLGrammarException: could not prepare statement
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123) ~[hibernate-core-4.2.6.Final.jar:4.2.6.Final]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) ~[hibernate-core-4.2.6.Final.jar:4.2.6.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) ~[hibernate-core-4.2.6.Final.jar:4.2.6.Final]
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:188) ~[hibernate-core-4.2.6.Final.jar:4.2.6.Final]
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:159) ~[hibernate-core-4.2.6.Final.jar:4.2.6.Final]
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1859) ~[hibernate-core-4.2.6.Final.jar:4.2.6.Final]
Caused by: org.h2.jdbc.JdbcSQLException: Kolumna "MEDICALINC0_._EBEAN_INTERCEPT" nie istnieje
Column "MEDICALINC0_._EBEAN_INTERCEPT" not found; SQL statement:
select medicalinc0_.id as id1_0_0_, medicalinc0_._ebean_intercept as _ebean_i2_0_0_, medicalinc0_.age as age3_0_0_, medicalinc0_.incident_type as incident4_0_0_, medicalinc0_.month as month5_0_0_, medicalinc0_.place as place6_0_0_, medicalinc0_.unit as unit7_0_0_ from MedicalIncident medicalinc0_ where medicalinc0_.id=? [42122-172]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329) ~[h2.jar:1.3.172]
at org.h2.message.DbException.get(DbException.java:169) ~[h2.jar:1.3.172]
at org.h2.message.DbException.get(DbException.java:146) ~[h2.jar:1.3.172]
at org.h2.expression.ExpressionColumn.optimize(ExpressionColumn.java:144) ~[h2.jar:1.3.172]
at org.h2.expression.Alias.optimize(Alias.java:52) ~[h2.jar:1.3.172]
at org.h2.command.dml.Select.prepare(Select.java:808) ~[h2.jar:1.3.172]
我不明白:我在conf中有精确的jpa:
application.name="SupraCIRS"
application.lang.cookie=SUPRACIRS_LANG
application.secret="r5Wd;ABfd7;e^F3p9WUl2132Y13v213g12K3ljoIdsg`MU8`YL:x`8KAhgao21ofwb?iQJe6hL0I6liIg121211"
application.langs="pl"
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:SupraCIRS"
db.default.jndiName=DefaultDS
jpa.default=defaultPersistenceUnit
ebeanEnabled=false
logger.root=ERROR
logger.play=INFO
logger.application=DEBUG
http.port=8081
file build.sbt
import play.Project._
name := """SupraCIRS"""
version := "1.0-Alfa"
libraryDependencies ++= Seq(
"org.webjars" %% "webjars-play" % "2.2.0",
"org.webjars" % "bootstrap" % "2.3.1")
libraryDependencies ++= Seq(javaJdbc, javaEbean)
libraryDependencies ++= Seq(
"org.hibernate" % "hibernate-entitymanager" % "4.2.6.Final",
"mysql" % "mysql-connector-java" % "5.1.18",
jdbc,
javaCore,
javaJdbc,
javaJpa
)
playJavaSettings
CONF / META-INF / persistence.xml中
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
</properties>
</persistence-unit>
</persistence>
请求帮助
答案 0 :(得分:1)
问题在于:libraryDependencies ++= Seq(javaJdbc, javaEbean)
。删除javaEbean
部分!这也应该解决你所有的其他问题。
答案 1 :(得分:-1)
解决方案:
我下载干净的拉链拉链。 并创建新项目。 然后我将dir应用程序配置从我的旧项目公开到新创建的。