Java/Framework & Libs

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

허니몬 2013. 4. 25. 13:36

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

개발환경

  • hibernate : 4.2.0.Final
    • hibernate dialect : org.hibernate.dialect.MySQLDialect
  • MariaDB : 5.5.29-MariaDB

문제 로그

java.lang.reflect.InvocationTargetException

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.lang.reflect.Method.invoke(Method.java:601)

    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)

    at java.lang.Thread.run(Thread.java:722)

Caused by: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [insert into department(id, name, description, parent_id, createdDate) values(?, ?, ?, ?, ?)]; nested exception is java.sql.BatchUpdateException: Table 'database.department' doesn't exist

    at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:237)

    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)

    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:605)

    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617)

    at org.springframework.jdbc.core.JdbcTemplate.batchUpdate(JdbcTemplate.java:890)

    at org.springframework.jdbc.core.namedparam.NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(NamedParameterBatchUpdateUtils.java:40)

    at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.batchUpdate(NamedParameterJdbcTemplate.java:324)

    ... 6 more

Caused by: java.sql.BatchUpdateException: Table 'database.department' doesn't exist

    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2054)

    at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1467)

    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)

    at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:905)

    at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:890)

    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:589)

    ... 12 more

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'database.department' doesn't exist

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)

    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)

    at com.mysql.jdbc.Util.getInstance(Util.java:386)

    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)

    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)

    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)

    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)

    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)

    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)

    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)

    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)

    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2006)

    ... 17 more

[INFO] ------------------------------------------------------------------------

[INFO] BUILD FAILURE

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 10.762s

[INFO] Finished at: Wed Apr 24 22:06:17 KST 2013

[INFO] Final Memory: 43M/365M

[INFO] ------------------------------------------------------------------------

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project docs-flow-data-manager: An exception occured while executing the Java class. null: InvocationTargetException: PreparedStatementCallback; bad SQL grammar [insert into department(id, name, description, parent_id, createdDate) values(?, ?, ?, ?, ?)]; nested exception is java.sql.BatchUpdateException: Table 'database.department' doesn't exist -> [Help 1]

[ERROR]

[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

[ERROR] Re-run Maven using the -X switch to enable full debug logging.

[ERROR]

[ERROR] For more information about the errors and possible solutions, please read the following articles:

[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

해결책

  • 하이버네이트가 자동으로 @Entity를 이용하여 테이블을 생성할 때 기본은 클래스명을 따른다.
    • 대소문자를 구분하는 Database 에서는 이 부분이 문제를 일으키는 요인으로 추측된다.
  • @Entity 아래에 @Table(name=“TABLE_NAME”) 으로 테이블명을 대문자로 하여 강제적으로 선언했다.
  • 참조관계가 생성되는 부분들에 대해서도 @JoinTable(name=“JOIN_TABLE”)으로 지정해주는 것이 적절해보인다.