2017-11-14 15 views
0

私はSpring BootとWebSocketプロジェクトを使用していますが、出力メッセージを永続化(保存)しようとしたときにエラーが発生しました。 Iは、原因:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

Inout MessageMessage{id=null, from='Mark', text='I travel to Brazil'} 
    Output MessageOutputMessage{id=null, from='Mark', message='I travel to Brazil', topic='Travel', time=Tue Nov 14 10:53:06 BDT 2017} 
Hibernate: insert into output_message (from, message, time, topic) values (?, ?, ?, ?) 

エラーメッセージが以下に提供され、OutputMessageエンティティが提供される

@Controller 
public class ChatController { 

    @Autowired 
    private OutputMessageService outputMessageService; 

    @Autowired 
    private MessageService messageService; 

    @MessageMapping("/chat/{topic}") 
    @SendTo("/topic/messages") 
    public OutputMessage send(@DestinationVariable("topic") String topic, 
           Message message) throws Exception { 

     OutputMessage outputMessage = new OutputMessage(message.getFrom(), message.getText(), topic); 

     System.out.println("Inout Message" + message.toString()); 
     System.out.println("Output Message" + outputMessage.toString()); 

     outputMessageService.save(outputMessage); 
     messageService.save(message); 

     return outputMessage; 
    } 
} 

コントローラはここで

org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement 

Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement 
    at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:207) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.dialect.identity.GetGeneratedKeysDelegate.executeAndExtract(GetGeneratedKeysDelegate.java:57) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:42) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2803) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3374) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:619) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:273) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:254) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:299) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:317) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:272) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:178) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:109) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.jpa.event.internal.core.JpaPersistEventListener.saveWithGeneratedId(JpaPersistEventListener.java:67) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:189) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:132) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:58) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:775) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:748) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:753) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1146) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final] 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144] 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_144] 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144] 
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144] 


Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from, message, time, topic) values ('Mark', 'I travel to Brazil', '2017-11-14 10' at line 1 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_144] 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_144] 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_144] 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_144] 

を提供するエンティティを印刷

@Entity 
public class OutputMessage { 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private Long id; 

    private String from; 
    private String message; 
    private String topic; 
    private Date time = new Date(); 

    public OutputMessage() { 
    } 

    public OutputMessage(String from, String message, String topic) { 
     this.from = from; 
     this.message = message; 
     this.topic = topic; 
    } 

    public String getFrom() { 
     return from; 
    } 

    public void setFrom(String from) { 
     this.from = from; 
    } 

    public String getMessage() { 
     return message; 
    } 

    public void setMessage(String message) { 
     this.message = message; 
    } 

    public String getTopic() { 
     return topic; 
    } 

    public void setTopic(String topic) { 
     this.topic = topic; 
    } 

    public Date getTime() { 
     return time; 
    } 


    @Override 
    public String toString() { 
     return "OutputMessage{" + 
       "id=" + id + 
       ", from='" + from + '\'' + 
       ", message='" + message + '\'' + 
       ", topic='" + topic + '\'' + 
       ", time=" + time + 
       '}'; 
    } 
} 

リポジトリ、

public interface OutputMessageRepository extends CrudRepository<OutputMessage, Long> { 
} 

サービスの実装、

@Service 
public class OutputMessageServiceImpl implements OutputMessageService { 

    @Autowired 
    private OutputMessageRepository omRepository; 

    @Override 
    public List<OutputMessage> findAll() { 
     return (List<OutputMessage>) omRepository.findAll(); 
    } 

    @Override 
    public void save(OutputMessage outputMessage) { 
     omRepository.save(outputMessage); 
    } 
} 

がここでの問題は何ですか?

答えて

4

フィールド名のために起こっている可能性がありますfromhibernate.globally_quoted_identifiers=trueプロパティを追加してもう一度お試しください。これにより、すべてのデータベース識別子が引用されます。

+0

ヒントをありがとう。私は実際にフィールドの名前を変更し、それは正常に動作します – Arefe

+1

@AAAはいも動作します... – Hiren