2016-06-23 3 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"과 같은 bizzare 이름으로 열을 찾고있는 이유는 무엇입니까? 내 테이블이나 열과 관련이 없습니다.

나는 잠시 동안 구글 어라운드를 봤지만 설명 할 수있는 것이 아무것도 없었다.

누군가 여기서 나를 도울 수 있다면 매우 감사드립니다.

감사 (임은 확실 정말 아직 복잡한 아무것도 시도하지 메신저와 같은 단순해야한다)

+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

관련 문제