i am trying to create a simple hibernate application.It gives following error.how to solve that error

Binod Pant

MainClass.java

package com.binod.hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class MainClass {
   public static void main(String[] args) {

        StudentInfo studentInfo=new StudentInfo();
        studentInfo.setRollNo(1);
        studentInfo.setFirstName("Binod");
        studentInfo.setLastName("Pant");

        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
        Session session = sessionFactory.openSession();
        session.beginTransaction();
        // this would save the Student_Info object into the database
        session.save(studentInfo);  
        session.getTransaction().commit();
        session.close();
        sessionFactory.close();

    }
}

StudentInfo.java

package com.binod.hibernate;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="student")
public class StudentInfo {

    @Id
    private int rollNo;
    private String firstName,lastName;
    public int getRollNo() {
        return rollNo;
    }
    public void setRollNo(int rollNo) {
        this.rollNo = rollNo;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
 }

hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">   
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">
            org.hibernate.dialect.MySQLDialect
        </property>
        <property name="hibernate.connection.driver_class">
            com.mysql.jdbc.Driver
        </property>
        <!-- Assume test is the database name -->
        <property name="hibernate.connection.url">
            jdbc:mysql://localhost:3306/hibernatepractise
        </property>
        <property name="hibernate.connection.username">
            root
        </property>
        <property name="hibernate.connection.password">
            devbinod
        </property>
        <!-- show all executed sql -->
        <property name="show_sql">true</property>
        <!-- Drop Existing Table create new one -->
        <property name="hbm2ddl.auto">create</property>
        <!-- List of XML mapping files -->
        <mapping class="com.binod.hibernate.StudentInfo" />
    </session-factory>
</hibernate-configuration>

The Error is

    INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
    Hibernate: drop table if exists student
    Jun 11, 2017 8:28:10 AM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
    INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@134d26af] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
    Hibernate: create table student (rollNo integer not null, firstName varchar(255), lastName varchar(255), primary key (rollNo)) type=MyISAM
    Jun 11, 2017 8:28:10 AM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
    INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@331acdad] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
    Jun 11, 2017 8:28:10 AM org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
    WARN: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
    org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
        at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
        at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:440)
        at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreatorImpl.java:424)
        at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:315)
        at org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:166)
        at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:135)
        at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:121)
        at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:155)
        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 org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
        at com.binod.hibernate.MainClass.main(MainClass.java:16)
    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 'type=MyISAM' at line 1
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
        at com.mysql.jdbc.Util.getInstance(Util.java:408)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:943)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2486)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2444)
        at com.mysql.jdbc.StatementImpl.executeInternal(StatementImpl.java:845)
        at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:745)
        at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
        ... 13 more

    Jun 11, 2017 8:28:10 AM org.hibernate.tool.schema.internal.SchemaCreatorImpl applyImportSources
    INFO: HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@2e2ff723'
    Hibernate: insert into student (firstName, lastName, rollNo) values (?, ?, ?)
    Jun 11, 2017 8:28:10 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    WARN: SQL Error: 1146, SQLState: 42S02
    Jun 11, 2017 8:28:10 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    ERROR: Table 'hibernatepractise.student' doesn't exist
    Jun 11, 2017 8:28:10 AM org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release
    INFO: HHH000010: On release of batch it still contained JDBC statements
    Jun 11, 2017 8:28:10 AM org.hibernate.internal.ExceptionMapperStandardImpl mapManagedFlushFailure
    ERROR: HHH000346: Error during managed flush [org.hibernate.exception.SQLGrammarException: could not execute statement]
    Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
        at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1441)
        at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:491)
        at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3201)
        at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2411)
        at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:467)
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:146)
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:220)
        at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:68)
        at com.binod.hibernate.MainClass.main(MainClass.java:23)
    Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement
        at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.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.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
        at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3003)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3503)
        at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:89)
        at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:589)
        at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:463)
        at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
        at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
        at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1435)
        ... 9 more
    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'hibernatepractise.student' doesn't exist
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
        at com.mysql.jdbc.Util.getInstance(Util.java:408)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:943)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2490)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
        at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2079)
        at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2013)
        at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5104)
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1998)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:205)
        ... 18 more

I already created a student table.Hibernate drop table but don't create a new table.how to solve this problem.where is my mistake i can't find.

N00b Pr0grammer

MySQL dialect when changed from

`org.hibernate.dialect.MySQLDialect`

to

`org.hibernate.dialect.MySQL5Dialect`

should resolve your issue.

The reason for this to happen is that MySQL5Dialect works with type MyISAM

The problem is that the dialect org.hibernate.dialect.MySQLDialect is for MySQL 4.x or earlier. The fragment type=MyISAM that is generated by this dialect was deprecated in MySQL 4.0 and removed in 5.5.

There are quite a few documentations available for what dialects to use for what database engine types for MySQL alone.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I am trying to develop web services REST application.I have a no idea how to solve following error

I am trying to share a project in github using IntelliJ IDEA but i gives a following error

I am developing plugin give following error while activation gives

I am using elasticserach-1.4.1 and when I'm trying to create an index, I am getting the following error

How to solve following Error?

When I am trying to create a pipeline in amazon elastic transcoder using amazon console with IAM it gives me an error

I am trying to create udp socket and send a string through it. but it gives 10038 error at sendto()

I am trying to create a subscription but an error occurs

I am trying to define the following vector function, but keep getting an error

Getting Following Error When i am trying to generate .apk file

I am trying to run the following in Jupyter but it is showing shape error

How I solve this error, I am trying to train a ticket classification model

The id I am trying to add to use navigation in Kotlin gives an error

I am trying to install the drivers and the kernel gives me this error:

Trying to set a hub server for togetherjs application and i am using node.js to run the server i get the following error

Trying to create a signal R chat application but gives error

I'm trying to manipulate a simple props in React but it gives me an error

Am trying to maven install the apache-storm repo i cloned. And am getting the following error. How to resolve this?

I have a swing application using Netbeans. I am trying to insert user object to the database table. But I am getting following error

I am trying to create a set of rows by adding an ArrayList to each row, data being fetched from an API, but it gives an error

When i am trying to run this code i am getting the following error

Currently I am learning react, trying to create react app, when I try to run "npx parcel index.html" I am getting following error

How could I solve the error in the following code in tab navigation?

How can I solve the following error in React Native?

I am trying to deploy django application using heroku but getting error?

I am trying to create a custom validator outside the form but I am running into a error. How do I fix the code?

I am not able to get the currentActivity in unity,and i am getting the following error after the application is run in the device

how to resolve this error.....i am trying to implement custom firebase notification application

StorageService gives an error on GluonHQ framework - How do I solve this?