代码之家  ›  专栏  ›  技术社区  ›  MrSir

sql文件中的ScriptStatementFailedException

  •  1
  • MrSir  · 技术社区  · 9 年前

    我正在吃 org.springframework.jdbc.datasource.init.ScriptStatementFailedException

    SET @TEASER = '<p> Text Text Text</p>'
    SET @BODY = '<p> Lorem ipsum dolor sit amet</p>'
    
    insert into author(id,first_name,last_name,email) values(1,'Dan','Vega','DVega@gmail.com');
    insert into post(id,title,slug,teaser,body,author_id,posted_on) values(1,'Spring boot rocks','spring-boot-rocks',@TEASER,@BODY,1,CURRENT_TIMESTAMP);
    insert into post(id,title,slug,teaser,body,author_id,posted_on) values(2,'Spring boot is kew;','spring-boot-is-kewl',@TEASER,@BODY,1,CURRENT_TIMESTAMP);
    

    @Entity
    public class Post {
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String title;
    @Column(columnDefinition = "TEXT")
    private String body;
    @Column(columnDefinition = "TEXT")
    private String teaser;
    private String slug;
    @CreatedDate @Column(columnDefinition = "TIMESTAMP")
    private Date postedOn;
    @ManyToOne
    private Author author;
    // constructors, getters and setters
    

    错误-它对每个与Post类相关的类都会重复,在本例中,HomeController有一个自动连接的PostService类,该类具有PostRepository自动连接属性。

    Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'homeController': Unsatisfied dependency expressed through method 'setPostService' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'postService': Unsatisfied dependency expressed through method 'setPostRepository' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'postRepository': Cannot create inner bean '(inner bean)#3f6f9cef' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3f6f9cef': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/Talon/Desktop/java%20netbeans/01/SpringBootH2Demo/target/classes/data-h2.sql]: SET @TEASER = '<p> Text Text Text</p>' SET @BODY = '<p> Lorem ipsum dolor sit amet</p>' insert into author(id,first_name,last_name,email) values(1,'Dan','Vega','DVega@gmail.com'); nested exception is org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "SET @TEASER = '<p> Text Text Text</p>' SET[*] @BODY = '<p> Lorem ipsum dolor sit amet</p>' INSERT INTO AUTHOR(ID,FIRST_NAME,LAST_NAME,EMAIL) VALUES(1,'Dan','Vega','DVega@gmail.com') "; SQL statement:
    SET @TEASER = '<p> Text Text Text</p>' SET @BODY = '<p> Lorem ipsum dolor sit amet</p>' insert into author(id,first_name,last_name,email) values(1,'Dan','Vega','DVega@gmail.com') [42000-196]
    

    1 回复  |  直到 9 年前
        1
  •  0
  •   Urvashi Soni    9 年前

    您可能忘了在SET语句后加分号。

    设置@摘要='Text Text'; 如果可行的话,试试这个