Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Field 'ID' doesn't have a default value: org.hibernate.exception.GenericJDBCException: could not ins

 
Baktha Elumalai
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have two table like xydataa and fm4featuress

xydataa.hbm.cml

<?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">
<!-- Generated Mar 19, 2010 4:59:08 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class catalog="navl" name="test.Xydataa" table="xydataa">
<id name="id" type="java.lang.Integer">
<column name="ID"/>
<generator class="native"/>
</id>
<property name="longi" type="string">
<column name="Longi"/>
</property>
<property name="lat" type="string">
<column name="Lat"/>
</property>
<property name="altitude" type="int">
<column name="Altitude" not-null="true"/>
</property>
<property name="angle" type="int">
<column name="Angle" not-null="true"/>
</property>
<property name="satellite" type="int">
<column name="Satellite" not-null="true"/>
</property>
<property name="speed" type="int">
<column name="Speed" not-null="true"/>
</property>
<property name="objectId" type="int">
<column name="ObjectId" not-null="true"/>
</property>
<property name="clientId" type="int">
<column name="ClientId" not-null="true"/>
</property>
<property name="gpsTime" type="string">
<column length="19" name="GpsTime" not-null="true"/>
</property>
<property name="location" type="string">
<column name="Location"/>
</property>
<property name="city" type="string">
<column name="City"/>
</property>
<property name="state" type="string">
<column name="State"/>
</property>
<property name="distance" type="string">
<column length="100" name="Distance"/>
</property>
<property name="times" type="timestamp">
<column length="19" name="Times"/>
</property>
<many-to-one name="fm4featuress" class="test.Fm4Featuress" cascade="all" insert="false" update="false">
<column name="ID" not-null="false" />
</many-to-one>
</class>
</hibernate-mapping>

and

fm4featuress.hbm.xml

<?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">
<!-- Generated Mar 19, 2010 4:59:08 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class catalog="navl" name="test.Fm4Featuress" table="fm4featuress">
<id name="id" type="java.lang.Integer">
<column name="ID"/>
<generator class="native"/>
</id>
<property name="DataId" type="int">
<column name="DataId" not-null="true"/>
</property>
<property name="Value" type="int">
<column name="Value" not-null="true"/>
</property>
<set name="xydataa" table="xydataa" lazy="false">
<key>
<column name="ID" not-null="true"/>
</key>
<one-to-many class="test.Xydataa" />
</set>
</class>
</hibernate-mapping>


java code:



Fm4featuress.java



this is the main java file



I got the error like this

Stacktrace

INFO: Inserting xydataa
INFO: Hibernate: insert into navl.xydataa (Longi, Lat, Altitude, Angle, Satellite, Speed, ObjectId, ClientId, GpsTime, Location, City, State, Distance, Times) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
INFO: Done
INFO: Inserting Fm4Featuress
INFO: Xydata: 3762
INFO: Hibernate: insert into navl.fm4featuress (DataId, Value) values (?, ?)
WARNING: SQL Error: 1364, SQLState: HY000
SEVERE: Field 'ID' doesn't have a default value
SEVERE: null
org.hibernate.exception.GenericJDBCException: could not insert: [test.Fm4Featuress]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at tcplistener.Alldatabase.Database(Alldatabase.java:174)
at tcplistener.ModuleHandler.run(ModuleHandler.java:155)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.SQLException: Field 'ID' doesn't have a default value
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3562)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3494)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1960)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2114)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2696)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2105)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2398)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2316)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2301)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
... 18 more

please help me

what i am doing wrong in my code



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic