2017-07-05 9 views
1

Alien.java (Pojo Klasse), das ist mein pojo Klassejava.sql.SQLSyntaxErrorException: Table 'mydb.alien' existiert nicht

package com.me.Hive1; 
    import javax.persistence.Entity; 
    import javax.persistence.Id; 

    @Entity 
    public class Alien {   
     @Id 
     private int id; 
     private String name; 
     public int getId() 
     { 
      return id; 
     } 
     public void setId(int id) 
     { 
      this.id = id; 
     } 
     public String getName() 
     { 
      return name; 
     } 
     public void setName(String name) 
     { 
      this.name = name; 
     } 
    } 

App.java (Hauptklasse), dieses ist Hauptklasse.

package com.me.Hive1; 
      import org.hibernate.Session; 
      import org.hibernate.SessionFactory; 
      import org.hibernate.Transaction; 
      import org.hibernate.cfg.Configuration; 
      //MAIN CLASS 
      /** 
      * Hello world! 
      * 
      */ 
      public class App 
      { 
       public static void main(String[] args) 
       { 
        System.out.println("Hello World!"); 
        Alien a = new Alien(); 
        a.setId(101); 
        a.setName("bhanu"); 
        try{ 
        Configuration fact = new Configuration().configure().addAnnotatedClass(Alien.class); 
        SessionFactory sf = fact.buildSessionFactory(); 
        Session session = sf.openSession(); 
        Transaction t = session.beginTransaction(); 
        session.save(a); 
        t.commit(); 
        } 
        catch(Exception e) 
        { 
         e.printStackTrace(); 
        } 

       } 
      } 

Konfigurationsdatei (hibernate.cfg.xml), dies ist meine Hibernate-Konfigurationsdatei.

<?xml version="1.0" encoding="UTF-8"?><!--Configuration file--> 
     <!DOCTYPE hibernate-configuration PUBLIC 
       "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
       "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 
     <hibernate-configuration> 
      <session-factory> 
       <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
       <property name="hibernate.connection.password">root</property> 
       <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mydb</property> 
       <property name="hibernate.connection.username">root</property> 
       <property name="hibernate.hbm2dll.auto">create</property> 
       <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 
       <mapping class="com.me.Hive1.Alien" resource="Alien.hbm.xml"/> 
      </session-factory> 
     </hibernate-configuration> 

Alien.hbm.xml (Mapping-Datei), diese Mapping-Datei ist, ist es optional?

<?xml version="1.0"?> 
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
    <!-- Generated Jul 5, 2017 1:44:20 AM by Hibernate Tools 3.5.0.Final --> 
    <hibernate-mapping> 
     <class name="com.me.Hive1.Alien" table="alien"> 
      <id name="id" type="int"> 
       <column name="ID" /> 
       <generator class="assigned" /> 
      </id> 
      <property name="name" type="java.lang.String"> 
       <column name="NAME" /> 
      </property> 
     </class> 
    </hibernate-mapping> 

ich bin immer Ausnahme (Konsolenausgabe) ist dies die Ausnahme i bekommen werde, nicht wissen, i

Hello World! 
    Jul 05, 2017 4:13:18 PM org.hibernate.Version logVersion 
    INFO: HHH000412: Hibernate Core {5.2.10.Final} 
    Jul 05, 2017 4:13:18 PM org.hibernate.cfg.Environment <clinit> 
    INFO: HHH000206: hibernate.properties not found 
    Jul 05, 2017 4:13:19 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit> 
    INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final} 
    Jul 05, 2017 4:13:19 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure 
    WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!) 
    Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. 
    Jul 05, 2017 4:13:19 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 
    INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/mydb] 
    Jul 05, 2017 4:13:19 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 
    INFO: HHH10001001: Connection properties: {user=root, password=****} 
    Jul 05, 2017 4:13:19 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator 
    INFO: HHH10001003: Autocommit mode: false 
    Jul 05, 2017 4:13:19 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init> 
    INFO: HHH000115: Hibernate connection pool size: 20 (min=1) 
    Wed Jul 05 16:13:19 IST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. 
    Jul 05, 2017 4:13:19 PM org.hibernate.dialect.Dialect <init> 
    INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect 
    Jul 05, 2017 4:13:24 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions 
    WARN: SQL Error: 1146, SQLState: 42S02 
    Jul 05, 2017 4:13:24 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions 
    ERROR: Table 'mydb.alien' doesn't exist 
    Jul 05, 2017 4:13:24 PM org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release 
    INFO: HHH000010: On release of batch it still contained JDBC statements 
    Jul 05, 2017 4:13:24 PM org.hibernate.internal.ExceptionMapperStandardImpl mapManagedFlushFailure 
    ERROR: HHH000346: Error during managed flush [org.hibernate.exception.SQLGrammarException: could not execute statement] 
    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.me.Hive1.App.main(App.java:25) 
    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: java.sql.SQLSyntaxErrorException: Table 'mydb.alien' doesn't exist 
     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:536) 
     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:513) 
     at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:115) 
     at com.mysql.cj.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:1983) 
     at com.mysql.cj.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1826) 
     at com.mysql.cj.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2034) 
     at com.mysql.cj.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:1970) 
     at com.mysql.cj.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5001) 
     at com.mysql.cj.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1955) 
     at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:205) 
     ... 18 more 
+0

Auch wenn ich nicht verwenden ** Maven ** i die gleiche Ausnahme bin immer, ich von einer Woche versucht haben, dabei helfen mir keine Lösung bis jetzt jemand bitte thing.what ist der Grund ** ** für Dies?????????? –

+0

versuchen Sie Folgendes: @Column private String name; anstelle des privaten String-Namens; in Entitätsklasse – Nidhi257

+0

Können Sie Ihren genauen Tabellennamen freigeben oder Tabellen-SQL erstellen? –

Antwort

0

versuchen diese geschlagen ist -

In der Konfigurationsdatei ändere den Wert dieser Eigenschaft:

<property name="hibernate.hbm2ddl.auto" value="update" /> 

Hoffe das wird dir helfen;)

+0

schließlich habe ich etwas Kraftstoff zu laufen überwintern, vielen Dank –

Verwandte Themen