无法在 playframework 中使用 import.sql
unable to use import.sql in playframework
我正在尝试将初始数据库导入我的游戏应用程序,但出现以下错误:
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at end of input
完全错误:https://gist.github.com/rolandg/8e10e9be18a57a057e060bd9f02c6141
配置:
persistence.xml
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<!--Hibernate properties-->
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name = "hibernate.hbm2dll.import_files" value="conf/import.sql"/>
</properties>
</persistence-unit>
import.sql
INSERT INTO Usr (entrydate, email, birthdate, lastname, password, phone, username, firstname, superior) VALUES
('2016-01-01', 'rossi.mario@gmail.com', '1987-06-25', 'rossi', '123456', '0471287130', 'mario', '', '');
Usr.java
package models;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Date;
@Entity
public abstract class Usr {
@Id
@GeneratedValue private Long personId;
@Column public String username;
@Column private String password;
@Column private String firstname;
@Column private String lastname;
@Column private Date birthdate;
@Column private Date entrydate;
@Column private String email;
@Column private String phone;
// cons
public Usr() {
}
//getter
public Long getPersonId() {
return personId;
}
public String getUsername() {
return this.username;
}
public String getPassword() {
return this.password;
}
public String getFirstname() {
return this.firstname;
}
public String getLastname() {
return this.lastname;
}
public Date getBirthdate() {
return this.birthdate;
}
public Date getEntrydate() {
return this.entrydate;
}
public String getEmail() {
return this.email;
}
public String getPhone() {
return this.phone;
}
//setter
public void setUsername(String username) {
this.username = username;
}
public void setPersonId(Long personId) {
this.personId = personId;
}
public void setPassword(String password) {
this.password = password;
}
public void setFirstname(String vorname) {
this.firstname = vorname;
}
public void setLastname(String nachname) {
this.lastname = nachname;
}
public void setBirthdate(Date geburtsdatum) {
this.birthdate = geburtsdatum;
}
public void setEntrydate(Date eintritt) {
this.entrydate = eintritt;
}
public void setEmail(String email) {
this.email = email;
}
public void setPhone(String telefon) {
this.phone = telefon;
}
}
我做错了什么? table 已创建,但我的导入似乎有一些错误。sql/config。
请帮忙..
只需将以下行添加到 persistence.xml 即可允许 sql 语句包含多行。
<property name="hibernate.hbm2ddl.import_files_sql_extractor" value="org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor" />
source
我正在尝试将初始数据库导入我的游戏应用程序,但出现以下错误:
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at end of input
完全错误:https://gist.github.com/rolandg/8e10e9be18a57a057e060bd9f02c6141
配置: persistence.xml
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<properties>
<!--Hibernate properties-->
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name = "hibernate.hbm2dll.import_files" value="conf/import.sql"/>
</properties>
</persistence-unit>
import.sql
INSERT INTO Usr (entrydate, email, birthdate, lastname, password, phone, username, firstname, superior) VALUES
('2016-01-01', 'rossi.mario@gmail.com', '1987-06-25', 'rossi', '123456', '0471287130', 'mario', '', '');
Usr.java
package models;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Date;
@Entity
public abstract class Usr {
@Id
@GeneratedValue private Long personId;
@Column public String username;
@Column private String password;
@Column private String firstname;
@Column private String lastname;
@Column private Date birthdate;
@Column private Date entrydate;
@Column private String email;
@Column private String phone;
// cons
public Usr() {
}
//getter
public Long getPersonId() {
return personId;
}
public String getUsername() {
return this.username;
}
public String getPassword() {
return this.password;
}
public String getFirstname() {
return this.firstname;
}
public String getLastname() {
return this.lastname;
}
public Date getBirthdate() {
return this.birthdate;
}
public Date getEntrydate() {
return this.entrydate;
}
public String getEmail() {
return this.email;
}
public String getPhone() {
return this.phone;
}
//setter
public void setUsername(String username) {
this.username = username;
}
public void setPersonId(Long personId) {
this.personId = personId;
}
public void setPassword(String password) {
this.password = password;
}
public void setFirstname(String vorname) {
this.firstname = vorname;
}
public void setLastname(String nachname) {
this.lastname = nachname;
}
public void setBirthdate(Date geburtsdatum) {
this.birthdate = geburtsdatum;
}
public void setEntrydate(Date eintritt) {
this.entrydate = eintritt;
}
public void setEmail(String email) {
this.email = email;
}
public void setPhone(String telefon) {
this.phone = telefon;
}
}
我做错了什么? table 已创建,但我的导入似乎有一些错误。sql/config。 请帮忙..
只需将以下行添加到 persistence.xml 即可允许 sql 语句包含多行。
<property name="hibernate.hbm2ddl.import_files_sql_extractor" value="org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor" />
source