vlad wrote:
On a production setup or a real application, you'd need to use an automatic schema migration tool, like
Flyway.
Because this is just a test project, you can auto generate your schema:
Code:
<property name="hibernate.hbm2ddl.auto">update</property>
If you don't generate the DB schema automatically, then you'll need to do it manually according to what Hibernate expects to find in the DB according to your mappings.
Anyway, since you are using MySQL, using AUTO is quite a bad idea. Check out
this article for more details.
But, there's even more.
You decide to set the hibernate.id.new_generator_mappings property to false for no good reason. This property should be set to false only when migrating from Hibernate 4 to 5 while relying on hi/lo optimization for the sequence-based optimizers. I doubt that's you use case here.
What you need to do at this point is to:
1) Read the
Hibernate User Guide.
1) Read these
Hibernate tutorials on vladmihalcea.com.
Tks for the pointer.
Both strategies I attempted did not work out.
I attempted the first one which is 'native'... it gives me error :
No generator named 'native' is defined in the persistence unit.
Then, I followed the sequence strategy as per your tutorial.
However, I am still getting another error :
Code:
Initial SessionFactory creation failed.org.hibernate.MappingException: org.hibernate.dialect.MySQLDialect does not support pooled sequences
Aug 24, 2017 2:18:16 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [tutorController] in context with path [/Hi5S] threw exception [Servlet execution threw an exception] with root cause
org.hibernate.MappingException: org.hibernate.dialect.MySQLDialect does not support pooled sequences
at org.hibernate.dialect.Dialect.getCreateSequenceString(Dialect.java:905)
at org.hibernate.dialect.Dialect.getCreateSequenceStrings(Dialect.java:863)
at org.hibernate.tool.schema.internal.StandardSequenceExporter.getSqlCreateStrings(StandardSequenceExporter.java:28)
at org.hibernate.tool.schema.internal.StandardSequenceExporter.getSqlCreateStrings(StandardSequenceExporter.java:18)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:224)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:110)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:183)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:309)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:452)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
at util.HibernateUtil.<clinit>(HibernateUtil.java:18)
at DAOSql.tutorDAOImpl.insertTutor(tutorDAOImpl.java:42)
at Business.Manager.insertTutor(Manager.java:24)
at controller.tutorController.doPost(tutorController.java:128)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)