These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: could not perform insert in MYSQL database
PostPosted: Sun Aug 26, 2007 2:15 pm 
Newbie

Joined: Sun Aug 26, 2007 2:09 pm
Posts: 4
Location: INDIA
I am beginner and could not perform database insert.
everything else is mentioned below-

Hibernate version: - 3.0

Mapping documents:
<?xml version="1.0" ?>
<!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.mycompany.person.Person" table="PERSON" >
<id name="id" column="PERSON_ID" unsaved-value="id_value">
<generator class="native" />
</id>
<property name="personName" column="PERSON_NAME" type="string" />
<property name="addressLine1" column="ADDRESS_LINE_1" type="string" />
<property name="addressLine2" column="ADDRESS_LINE_2" type="string" />
<property name="addressCity" column="ADDRESS_CITY" type="string" />
<property name="addressState" column="ADDRESS_STATE" type="string" />
<property name="addressCountry" column="ADDRESS_COUNTRY" type="string" />
</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Session session=HibernateUtil.getSessionFactory( ).getCurrentSession( );
session.beginTransaction( );

Person thePerson=new Person( );
thePerson.setPersonName( personName );
thePerson.setAddressLine1( addressLine1 );
thePerson.setAddressLine2( addressLine2 );
thePerson.setAddressCity( addressCity );
thePerson.setAddressState( addressState );
thePerson.setAddressCountry( addressCountry );

session.save( thePerson );
session.getTransaction( ).commit( );


Full stack trace of any exception that occurs:

[java] Hibernate: insert into PERSON (PERSON_NAME, ADDRESS_LINE_1, ADDRESS_LINE_2, ADDRESS_CITY, ADDRESS_STATE, ADDRESS_COUNTRY) values (?, ?, ?, ?, ?, ?)
[java] Exception in thread "AWT-EventQueue-0" org.hibernate.exception.GenericJDBCException: could not insert: [com.mycompany.person.Person]
[java] at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
[java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
[java] at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2108)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2588)
[java] at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
[java] at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
[java] at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
[java] at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:180)
[java] at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
[java] at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
[java] at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
[java] at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
[java] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
[java] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:585)
[java] at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
[java] at $Proxy0.save(Unknown Source)
[java] at com.mycompany.person.PersonManager.createAndStorePerson(Unknown Source)
[java] at com.mycompany.gui.MainFrame.actionPerformed(Unknown Source)
[java] at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
[java] at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
[java] at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
[java] at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
[java] at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
[java] at java.awt.Component.processMouseEvent(Component.java:5501)
[java] at javax.swing.JComponent.processMouseEvent(JComponent.java:3135)
[java] at java.awt.Component.processEvent(Component.java:5266)
[java] at java.awt.Container.processEvent(Container.java:1966)
[java] at java.awt.Component.dispatchEventImpl(Component.java:3968)
[java] at java.awt.Container.dispatchEventImpl(Container.java:2024)
[java] at java.awt.Component.dispatchEvent(Component.java:3803)
[java] at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
[java] at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
[java] at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
[java] at java.awt.Container.dispatchEventImpl(Container.java:2010)
[java] at java.awt.Window.dispatchEventImpl(Window.java:1778)
[java] at java.awt.Component.dispatchEvent(Component.java:3803)
[java] at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
[java] at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
[java] at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
[java] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
[java] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
[java] at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
[java] Caused by: java.sql.SQLException: Field 'PERSON_ID' doesn't have a default value
[java] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
[java] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
[java] at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
[java] at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
[java] at com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
[java] at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1268)
[java] at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1541)
[java] at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1455)
[java] at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1440)
[java] at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
[java] at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
[java] ... 47 more

Name and version of the database you are using:
MySQL -server 5.0


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 26, 2007 3:15 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:44 pm
Posts: 33
Hi!

See the following line in your stacktrace:

Code:
Caused by: java.sql.SQLException: Field 'PERSON_ID' doesn't have a default value


It looks like PERSON_ID does not get a value.

Just to debug this issue you might try another generator, f.x.

Code:
<generator class="increment" />



-Kaj :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.