无法在playframework中使用import.sql

时间:2016-04-18 13:10:18

标签: hibernate postgresql playframework-2.5

我试图将初始数据库导入我的播放应用程序,但是我收到以下错误:

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;
        }

}

我做错了什么?该表已创建,但我的import.sql / config似乎有一些错误。 请帮忙..

1 个答案:

答案 0 :(得分:0)

只需将以下行添加到persistence.xml以允许包含多行的sql语句。

<property name="hibernate.hbm2ddl.import_files_sql_extractor" value="org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor" />

source