Wednesday, 23 September 2015

The database returned no natively generated identity value; nested exception is org.hibernate.HibernateException: The database returned no natively generated identity value

Several reasons are there for this issue :


Why ?
IDENTITY ID generator with a table column which is not properly configured. It should be an auto_increment column for the IDENTITY generator to work. Else, the database doesn't return any generated ID.

How to solve?
1) And fixing this is as simple as making sure that the Primary Key Column, of the table you are working with, has Auto Increment set.

 2) In such scenario, you not need to create table manually. It will create by default using hibernate. make change or add in hibernate.cfg.xml >> "hibernate.hbm2ddl.auto" field set to "update".

3) We must auto_increment the id column of the table by using below query
   ALTER TABLE document MODIFY COLUMN document_id INT auto_increment

PLEASE COMMENT YOUR SOLUTION IF YOU FOUND BY OTHER WAY

Tuesday, 8 September 2015

Eclipse “Error: Could not find or load main class”

Some time eclipse not run any java file and give exception like
"Error: Could not find or load main class"

Bellow are few solution :

Solution 1 )
  • went to run configurations: - run->run configurations
      In the Classpath tab:
  • Select Advanced
  • Add where Eclipse usually put the *.class for the projects, which is in bin. So I added the bin directory for the project.
Solution 2)
   
  • Project -> Clean will remove any existing class files and completely rebuild the project.
Solution 3)

It seems that the class is not compiled by Eclipse.
Few pointers could be-
  1. Check if the .class file exists in your output folder.To know your output folder Right Click on Project->Properties->Java Build Path(Check at bottom).
  2. Check if Project->build Automatically is checked in the menu.
  3. Check if the HelloWorld class is in src folder or not.Right Click on Project->Properties->Java Build Path(Check source tab).