Must the table name in database exactly the same as Models?


#1

Hi expert,

My recent debug told me that my tables do not exist but it is there in MySQL.

Now, I found out from https://dev.mysql.com/doc/refman/5.7/en/cannot-find-table.html that the name has to be same and case sensitive.

Now, my tables name even though are same as Models they differ in the first character.
For example, I have subject table but my Models is Subject.

The error I am getting now :

Error accessing tables metadata
	at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExcepti
onTypeDelegate.java:63)
	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(Stand
ardSQLExceptionConverter.java:42)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.
java:111)
	at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.
java:97)
	at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseM
etaDataImpl.convertSQLException(InformationExtractorJdbcDatabaseMetaDataImpl.jav
a:98)
	at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseM
etaDataImpl.populateTablesWithColumns(InformationExtractorJdbcDatabaseMetaDataIm
pl.java:383)
	at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseM
etaDataImpl.getTables(InformationExtractorJdbcDatabaseMetaDataImpl.java:337)
	at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.getTables
Information(DatabaseInformationImpl.java:120)
	at org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl.performTablesMi
gration(GroupedSchemaMigratorImpl.java:65)
	at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(A
bstractSchemaMigrator.java:203)
	at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(Abstra
ctSchemaMigrator.java:110)
	at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabas
eAction(SchemaManagementToolCoordinator.java:183)
	at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(Schema
ManagementToolCoordinator.java:72)
	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:309
)
	at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBu
ilderImpl.java:452)
	at util.HibernateUtil.getSessionFactory(HibernateUtil.java:42)
	at Business.RegisterService.register(RegisterService.java:24)
	at controller.tutorController.doPost(tutorController.java:88)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:166)
	at org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.
java:71)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:199)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase
.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140
)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogVa
lve.java:651)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:417)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java
:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtoco
l.java:754)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.jav
a:1376)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:
49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.ja
va:61)
	at java.lang.Thread.run(Unknown Source)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'hi5
s.subject' doesn't exist
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

My question is :

  1. how to overcome this table not found error?
  2. do i need to alter the model such that the Subject to becomes subject - cos my database is using small cap subject?

#2

Hi @karengsh,

MySQL on Linux is case sensitive, you can use the @Table annotation specifying the name you want to use for the table, by example :

@Entity
@Table(name"subject")
public class Subject{
.....
}

this should solve your problem.


#3

Hi dreab8,

I had that

@Entity (name = “Subject”)
@Table(name = “subject”)
public class Subject implements Serializable {

But, it did not help me to resolve the table not exists but it is actually there.

BTW, I do want to highlight that the column name inside differs and I have yet to correct it (but still trying to figure how to do it). But then it should not give me table not exists right ? The column name different is another story right ?


#4

Error accessing tables metadata

You did not add the entire stack trace, so it’s not clear what went wrong.

Add the entire stack trace and then we shall see.

The column name different is another story right ?

Add the mappings and the database table schema to your question as well. Otherwise, we won;t be able to help you.