Posts

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,

String rotation interview question for 5 Years of exprience

After long time I have got time to update my blog and help to the followers. These are the most commonly asking interview questions in string concept in java. String Rotation: How can you find one string is the rotation of another string? As we all know what the rotation means is, moving the first character of the string into last. When you keep doing the same, after certain moves you will get the initial string. This is what String Rotation is. Let say I have two strings as mentioned in the below, String str1 = “ABCDEF”; String str2 = “DEFABC”; Now, apply your logic to find str1 is the rotation of str2 or in reverse. First try your own, if not follow the below logic. This is also one of the CMMI Level5 company interview question. Steps to solve the above problem: If you want to find str1 is the rotation of str2. Let’s do concatenation of str2 with it. Means String str3 = str2+str2; Find the str3 contains the str1 or not by using the contains () method

Hibernate CRUD operations with example

Read this article to know what is CRUD and how to do CRUD operations in hibernate with example. CRUD stands for Create, Read, Update and Delete. As part of hibernate learning CRUD operations are the most basic operations. In previous examples, I have explained by using the MySQL configuration in Hibernate. But, in the current example, I am explaining by using Oracle as well as MySQL configuration. The choice is yours, use at your convenience. As of you people already know if we have to change the Database vendors no need to rewrite the entire code, it’s just a configuration file change. So, except the hibernate.cfg.xml file remaining all files logic will be common for both of the databases like Oracle or MySQL. Before going to write the hibernate logic, we have small work with the databases either Oracle or MySQL. Execute the below query to create the table in the database. Before going to execute the below query make sure you have connected with the specific Schema in the dat