-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: WARN: SQL Error: 942, SQLState: 42000
PostPosted: Wed Nov 30, 2016 12:54 pm 
Newbie

Joined: Wed Nov 30, 2016 12:47 pm
Posts: 4
Hello Everybody,
I am trying a simple Hibernate program.The programs and stck trace are as follows,

Could you pl. look into it.
Hibernate.cfg.xml

Code:
<!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.dialect">org.hibernate.dialect.Oracle10gDialect</property>
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.username">system</property>
        <property name="hibernate.connection.password">qwerty1uiop</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
        <property name="hibernate.hbm22ddl.auto">update</property>
        <property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
        <property name="show_sql">true</property>
        <property name="org.hibernate">debug</property>
        <property name="use_sql_comments">true</property>
        <mapping resource="com/wipro/Person.hbm.xml"/>       
    </session-factory>
</hibernate-configuration>


Person.hbm.xml

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">



<hibernate-mapping package="com.wipro">

    <class name="Person" table="PERSON">
            <id name="id" column="Person_ID" type="int">
                <generator class="native"/>
           </id>         
           
          <property name="firstName" />
            <property name="lastName" />
       
    </class>

</hibernate-mapping>


Code:
package com.wipro;

public class Person {
//every attribute should begin with small letter
   //this is called a pojo in Hibernate.Only properties,stters an getters
   private Integer id;
   private String firstName;
   private String lastName;
   public Integer getId() {
      return id;
   }
   public void setId(Integer id) {
      this.id = id;
   }
   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;
   }
}


Code:
package com.wipro;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

public class Manager1 {
public static void main(String[] args) {
   Person p1=new Person();
   p1.setId(101);
   p1.setFirstName("suresh");
   p1.setLastName("sankar");
   
   Configuration c1=new Configuration();
   c1.configure();
   ServiceRegistry sr=new ServiceRegistryBuilder().applySettings(c1.getProperties()).buildServiceRegistry();
   SessionFactory sf=c1.buildSessionFactory(sr);
   Session s1=sf.openSession();
   s1.beginTransaction();
   s1.save(p1);
   //s1.getTransaction().commit();
   s1.getTransaction().commit();
   s1.flush();
   s1.close();
   System.out.println("done");
}
}


Hibernate.properties

Code:
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\mkapp.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%c] - %m%n

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

# Root logger option
log4j.rootLogger=INFO, file, stdout

# Log everything. Good for troubleshooting
log4j.logger.org.hibernate=INFO

# Log all JDBC parameters
log4j.logger.org.hibernate.type=ALL
log4j.logger.org.hibernate.SQL=debug


Code:
Nov 30, 2016 4:47:19 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000422: Disabling contextual LOB creation as connection was null
Nov 30, 2016 4:47:19 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Nov 30, 2016 4:47:19 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Hibernate: /* insert com.wipro.Person */ insert into PERSON (firstName, lastName, Person_ID) values (?, ?, ?)
Nov 30, 2016 4:47:20 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 942, SQLState: 42000
Nov 30, 2016 4:47:20 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ORA-00942: table or view does not exist

Nov 30, 2016 4:47:20 PM org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release
INFO: HHH000010: On release of batch it still contained JDBC statements
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute statement
   at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123)
   at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)


Top
 Profile  
 
 Post subject: Re: WARN: SQL Error: 942, SQLState: 42000
PostPosted: Wed Nov 30, 2016 3:20 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I see that you use HBM2DDL update, which means the tables should have been created when you started the application.

However, there was an error when the schema was generated, and you omitted to add it in the stack trace.

Try setting:

Code:
<property name="hibernate.hbm2ddl.halt_on_error">true</property>


Top
 Profile  
 
 Post subject: Re: WARN: SQL Error: 942, SQLState: 42000
PostPosted: Thu Dec 01, 2016 7:33 am 
Newbie

Joined: Wed Nov 30, 2016 12:47 pm
Posts: 4
Hi Thorben,

Thanks for the reply.

I made changes as per your suggestion and also changed hibernate.hbm22ddl.auto to create,but with little success.configuration and Log below,
<!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.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">system</property>
<property name="hibernate.connection.password">qwerty1uiop</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
<property name="hibernate.hbm22ddl.auto">create</property>
<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
<property name="show_sql">true</property>
<property name="org.hibernate">debug</property>
<property name="use_sql_comments">true</property>
<property name="hibernate.hbm2ddl.halt_on_error">true</property>
<mapping resource="com/wipro/Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>

--------------------------------------
<hibernate-mapping package="com.wipro">

<class name="Person" table="PERSON">
<id name="id" column="Person_ID" type="int">
<!-- <generator class="native" />-->
</id>

<property name="firstName" />
<property name="lastName" />

</class>

</hibernate-mapping>
======================
Dec 01, 2016 4:26:22 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
Dec 01, 2016 4:26:22 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.21.Final}
Dec 01, 2016 4:26:22 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {log4j.logger.org.hibernate.type=ALL, log4j.appender.stdout=org.apache.log4j.ConsoleAppender, log4j.rootLogger=INFO, file, stdout, log4j.appender.file.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%c] - %m%n, log4j.appender.file.File=C:\mkapp.log, log4j.logger.org.hibernate=INFO, log4j.appender.file.layout=org.apache.log4j.PatternLayout, log4j.appender.file.MaxBackupIndex=1, log4j.logger.org.hibernate.SQL=debug, log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n, log4j.appender.file.MaxFileSize=1MB, log4j.appender.file=org.apache.log4j.RollingFileAppender, hibernate.bytecode.use_reflection_optimizer=false, log4j.appender.stdout.layout=org.apache.log4j.PatternLayout, log4j.appender.stdout.Target=System.out}
Dec 01, 2016 4:26:22 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Dec 01, 2016 4:26:22 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Dec 01, 2016 4:26:22 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Dec 01, 2016 4:26:23 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: com/wipro/Person.hbm.xml
Dec 01, 2016 4:26:23 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Dec 01, 2016 4:26:23 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Dec 01, 2016 4:26:23 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
Dec 01, 2016 4:26:23 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: false
Dec 01, 2016 4:26:23 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [oracle.jdbc.driver.OracleDriver] at URL [jdbc:oracle:thin:@localhost:1521:XE]
Dec 01, 2016 4:26:23 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=system, password=****}
Dec 01, 2016 4:26:23 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
Dec 01, 2016 4:26:23 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000422: Disabling contextual LOB creation as connection was null
Dec 01, 2016 4:26:24 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Dec 01, 2016 4:26:24 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Hibernate: /* insert com.wipro.Person */ insert into PERSON (firstName, lastName, Person_ID) values (?, ?, ?)
Dec 01, 2016 4:26:26 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 942, SQLState: 42000
Dec 01, 2016 4:26:26 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ORA-00942: table or view does not exist

Dec 01, 2016 4:26:26 PM org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release
INFO: HHH000010: On release of batch it still contained JDBC statements
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute statement
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:189)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:59)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3079)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3521)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:395)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:387)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:303)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:349)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1195)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)
at com.wipro.Manager1.main(Manager1.java:23)
Caused by: java.sql.SQLException: ORA-00942: table or view does not exist

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:837)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1010)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1315)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3576)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3657)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1062)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:186)
... 14 more


Top
 Profile  
 
 Post subject: Re: WARN: SQL Error: 942, SQLState: 42000
PostPosted: Thu Dec 01, 2016 7:43 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Hi,

My name is Vlad, not Thorben :D

Try with Hibernate 5.2.5 and see if it works.

Vlad


Top
 Profile  
 
 Post subject: Re: WARN: SQL Error: 942, SQLState: 42000
PostPosted: Thu Dec 01, 2016 9:46 am 
Newbie

Joined: Wed Nov 30, 2016 12:47 pm
Posts: 4
Thanks Vlad.
Tried with 5.2.3 version of Hibernate jars,but in vain.
The stack trace is the same as in the beginning.


Top
 Profile  
 
 Post subject: Re: WARN: SQL Error: 942, SQLState: 42000
PostPosted: Thu Dec 01, 2016 10:21 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I found the issue. You have a typo:

Instead of:

Code:
<property name="hibernate.hbm22ddl.auto">create</property>


You should have:

<property name="hibernate.hbm2ddl.auto">create</property>

Gotcha!


Top
 Profile  
 
 Post subject: Re: WARN: SQL Error: 942, SQLState: 42000
PostPosted: Fri Dec 02, 2016 8:41 am 
Newbie

Joined: Wed Nov 30, 2016 12:47 pm
Posts: 4
Thanks Vlad.

It is working now.A silly mistake on my part.
Thanks for all the trouble you took.


Top
 Profile  
 
 Post subject: Re: WARN: SQL Error: 942, SQLState: 42000
PostPosted: Fri Dec 02, 2016 10:05 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You're welcome.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.