Posts

Showing posts with the label Hibernate

java.sql.SQLException: ORA-00926: missing VALUES keyword

As part of Hibernate auto increment practice, I have entered into multiple issue. Here is the one of the exception which I had entered into is  java.sql.SQLException : ORA-00926: missing VALUES keyword . Stacktrace is as follows, Apr 10, 2017 4:48:37 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions WARN: SQL Error: 926, SQLState: 42000 Apr 10, 2017 4:48:37 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions ERROR: ORA-00926: missing VALUES keyword Apr 10, 2017 4:48:37 PM org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release INFO: HHH000010: On release of batch it still contained JDBC statements Apr 10, 2017 4:48:37 PM org.hibernate.internal.SessionImpl$5 mapManagedFlushFailure ERROR: HHH000346: Error during managed flush [could not execute statement] Exception in thread "main"  org.hibernate.exception.SQLGrammarException : could not execute statement        at org.hibernate.exception.internal.SQLStateConve

ExceptionInInitializerError in Hibernate

As part of the Hibernate practice, I have faced the  Exception in thread "main" java.lang.ExceptionInInitializerError  at the time of creating the SessionFactory. Here is the full stacktrace which I have captured from console. INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException SessionFactory creation failed.org.hibernate.boot.registry.classloading.spi.ClassLoadingException : Unable to load class [com.javatbrains.sample.User] Exception in thread "main" java.lang.ExceptionInInitializerError        at com.jtb.util.HibernateUtil.buildSessionFactory( HibernateUtil.java:13 )        at com.jtb.util.HibernateUtil.getSessionFactory( HibernateUtil.java:18 )        at com.jtb.test.DeleteUser.main( DeleteUser.java:11 ) Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException : Unable to load class [com.javatbrains.sample.User]        at org.hibernate.

SessionFactory creation failed.java.lang.NoSuchFieldError: namingStrategy

While creating the SessionFactory in Hibernate I have faced lot's of issues. This is also one the exception which I have faced, SessionFactory creation failed.java.lang.NoSuchFieldError: namingStrategy Exception in thread "main" java.lang.ExceptionInInitializerError        at com.jtb.util.HibernateUtil.buildSessionFactory( HibernateUtil.java:13 )        at com.jtb.util.HibernateUtil.getSessionFactory( HibernateUtil.java:18 )        at com.jtb.test.DeleteUser.main( DeleteUser.java:11 ) Caused by: java.lang.NoSuchFieldError: namingStrategy        at org.hibernate.cfg.AnnotationConfiguration.reset( AnnotationConfiguration.java:237 )        at org.hibernate.cfg.Configuration.<init>( Configuration.java:125 )        at org.hibernate.cfg.Configuration.<init>( Configuration.java:119 )        at org.hibernate.cfg.AnnotationConfiguration.<init>( AnnotationConfiguration.java:96 )        at com.jtb.util.HibernateUtil.buildSessionFactory( Hiber

SessionFactory creation failed.java.lang.NoClassDefFoundError

While practicing the Hibernate auto increment example, I have faced lots of issues. In that one of the thing is SessionFactory creation error. Error stack trace is as follows, SessionFactory creation failed.java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory Exception in thread "main" java.lang.ExceptionInInitializerError        at com.jtb.util.HibernateUtil.buildSessionFactory( HibernateUtil.java:15 )        at com.jtb.util.HibernateUtil.<clinit>( HibernateUtil.java:8 )        at com.jtb.test.DeleteUser.main( DeleteUser.java:11 ) Caused by: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory        at org.hibernate.cfg.AnnotationConfiguration.<clinit>( AnnotationConfiguration.java:65 )        at com.jtb.util.HibernateUtil.buildSessionFactory( HibernateUtil.java:12 )        ... 2 more Caused by: java.lang.ClassNotFoundException : org.apache.commons.logging.LogFactory        at java.net.URLClassLoad

Hibernate CRUD operations with auto increment in Oracle SQL with examples

Image
Previously I was explained Hibernate CRUD Operations without Auto Increment column. Here I am explaining how to do Hibernate CRUD operations with Primary key column as auto increment in Oracle SQL with examples. There will be slight difference in pseudo code compare to the previous example. But, mostly the same classes I have used to maintain the consistency. Before going to write the java logic, we have small work to do in the database to create the table and sequence. Please execute the below lines of SQL script in your SQL prompt or SQL developer. To create the table with primary key: create table USER_INFO(user_id NUMBER,user_name VARCHAR2(50),password VARCHAR2(50),CONSTRAINT user_id_pk PRIMARY KEY(user_id)); To alter the Primary Key Constraint: alter table USER_INFO ADD CONSTRAINT user_id_pk primary key(user_id); To create the sequence: create sequence user_sequence start with 1 increment by 1 nomaxvalue; That's it we are done with our work in database side. Now,