Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Issue in hibernate after modifying generator class from increment to identity

 
Sandy Java Geek
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a simple user.hmb.xml file to create a database table.
I just modified the generator class from increment to identity and now it throws SQL exception : java.sql.SQLException: Field 'ID' doesn't have a default value
Below is the User.hbm.xml file and the POJO User.java

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.model.User" table="user_master">
<id name="id" type="java.lang.Integer" column="ID">
<generator class="identity"></generator>
</id>

-----------------------------------------------------------------------------------------------------
User.java

 
Randy Maddocks
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sandy,

Welcome to JavaRanch!  

The issue could have something to do with your database schema. Perhaps this will help: Generation type identity gives error

Cheers!
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!