2016-06-23 5 views
0

私はjpa/hibernateを使うために私の春のブートプロジェクトに適応し始めています。この段階では、mysqlデータベース内のテーブルのIDを取得したいだけです。ポストテーブルのHibernateは存在しない列は分かっていません...明らかに

@SpringBootApplication 
@ComponentScan(basePackages = {"rest.api.controller", "dao",  rest.api.model", "rest.api.config"}) 

public class Application { 

public static void main(String[] args) { 
    SpringApplication.run(Application.class, args); 

} 

@Bean 
public CommandLineRunner demo(PostRepository repository) { 
    return (args) -> { 
     // save a couple of customers 
     repository.findAll(); 
    }; 
} 

}

@Entity 
@Table(name="post") 
public class Post { 

    private String text; 

    @Id 
    @GeneratedValue(strategy= GenerationType.AUTO) 
    @Column(name="id") 
    private long id; 

    @Column(name="sender_id") 
    private @JsonIgnore long senderId; 
    private @JsonIgnore long eventId; 
    private @JsonIgnore final String selectSql = " text, sender_id, event_id"; 

    protected Post() {} 

    public Post(long id, float latitude, float longitude, Date created, String ip, 
       String text, long senderId, long eventId) { 
     this.text = text; 
     this.senderId = senderId; 
     this.eventId = eventId; 
    } 

    public Post(String text, long senderId, long eventId) { 
     this.text = text; 
     this.senderId = senderId; 
     this.eventId = eventId; 
    } 

    public String getText() { 
     return text; 
    } 

    public long getSenderId() { 
     return senderId; 
    } 

    public long getEventId() { 
     return eventId; 
    } 

    public void setId(long id) { 
     this.id = id; 
    } 
} 

public interface PostRepository extends CrudRepository<Post, Long> { 

} 

とMySQL::ここで

は、関連するクラスである私は、次のようなエラーに取得

CREATE TABLE `post` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT, 
    `text` varchar(4096) NOT NULL, 
    `sender_id` bigint(20) NOT NULL, 
    `event_id` bigint(20) DEFAULT NULL, 
    `created` datetime NOT NULL, 
    `ip` varchar(20) NOT NULL, 
    `latitude` float DEFAULT NULL, 
    `longitude` float DEFAULT NULL, 
    `deleted` tinyint(1) NOT NULL DEFAULT '0', 
    PRIMARY KEY (`id`), 
    KEY `post_sent_by_user` (`sender_id`), 
    CONSTRAINT `post_sent_by_user` FOREIGN KEY 

2016-06-23 20:39:06.739 WARN 6895 --- [   main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1054, SQLState: 42S22 
2016-06-23 20:39:06.740 ERROR 6895 --- [   main] o.h.engine.jdbc.spi.SqlExceptionHelper : Unknown column 'post0_.select_sql' in 'field list' 
2016-06-23 20:39:06.750 WARN 6895 --- [   main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning Code: 1054, SQLState: 42S22 
2016-06-23 20:39:06.751 WARN 6895 --- [   main] o.h.engine.jdbc.spi.SqlExceptionHelper : Unknown column 'post0_.select_sql' in 'field list' 
2016-06-23 20:39:06.770 ERROR 6895 --- [   main] o.s.boot.SpringApplication    : Application startup failed 

java.lang.IllegalStateException: Failed to execute CommandLineRunner 
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:809) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE] 
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:790) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE] 
    at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:777) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE] 
    at rest.api.Application.main(Application.java:16) [main/:na] 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_91] 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_91] 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_91] 
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_91] 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) [idea_rt.jar:na] 
Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet 
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:242) ~[spring-orm-4.2.6.RELEASE.jar:4.2.6.RELEASE] 

"post0_.select_sql"という名前のような名前の列を探している理由は、私の人生の中ではわかりません。私のテーブルや列には関係しません。

私はしばらくの間、グーグルグーグルを行ったが、これを説明するための何も見つかりませんでした。

誰かが私をここで助けてくれたら非常に感謝します。

おかげで(イムは確かにそれは実際にはまだ複雑な何かをしようとしていないイムとして簡単であるべき)

+0

クエリログを有効にして、失敗している完全なクエリを確認します。それは参考になるかもしれません:http://stackoverflow.com/questions/30118683/how-to-log-sql-statements-in-spring-boot –

答えて

0

あなたのエンティティが永続フィールドがそのよう名付けられたその休止状態に語ったので:

private @JsonIgnore final String selectSql 

ノーを持っているがこのフィールドが何であるか、それがあなたのエンティティにある理由ですが、おそらく他の場所にあるか、少なくとも定数として定義されていなければなりません(つまり、staticに作られています)、または少なくとも@Transientによって注釈が付けられているので、Hibernateは、永続プロパティ。

+0

ありがとうございます。私はそこで全く盲目的だった。私は本当になぜこれもそこにいたのか分かりません。今でもうまく動作します – gezinspace

関連する問題