-->
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.  [ 7 posts ] 
Author Message
 Post subject: Caused by: ERROR 42Z23: Attempt to modify an identity column
PostPosted: Sun Jun 15, 2008 11:31 pm 
Newbie

Joined: Sun Jun 15, 2008 11:16 pm
Posts: 3
Location: philppines
Hi,

I'm new to hibernate and I encounter an error when I'm trying to save a new persistent data.

Here is my sample code:

From my client:
DataStore data = new DataStore("data3", "types3");
DatabaseDemoService.Util.getInstance().populateData(data, new AsyncCallback<List>() {
...
}
this my server implementation:
public void populateData(DataStore data) {
try {
final DataStore data1 = new DataStore(data);
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
session.save(data1);
session.getTransaction().commit();
} catch (HibernateException e) {
e.printStackTrace();
}

}

This are my errors: what could posibly wrong with my sample code. I'm trying to integrate Google Web Toolkit and Hibernate.

org.hibernate.exception.SQLGrammarException: could not insert: [com.org.sample.driftmark.client.DataStore]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2267)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.org.sample.driftmark.server.DatabaseDemoServiceImpl.populateData(DatabaseDemoServiceImpl.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:527)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:163)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:85)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at com.google.gwt.dev.shell.GWTShellServlet.service(GWTShellServlet.java:290)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.SQLSyntaxErrorException: Attempt to modify an identity column 'ID'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement40.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver40.newEmbedPreparedStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:94)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2224)
... 46 more
Caused by: java.sql.SQLException: Attempt to modify an identity column 'ID'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 64 more
Caused by: ERROR 42Z23: Attempt to modify an identity column 'ID'.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.compile.ResultColumnList.checkAutoincrement(Unknown Source)
at org.apache.derby.impl.sql.compile.InsertNode.enhanceAndCheckForAutoincrement(Unknown Source)
at org.apache.derby.impl.sql.compile.InsertNode.bindStatement(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
... 58 more

Thanks,
Madz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 16, 2008 7:26 am 
Beginner
Beginner

Joined: Tue Dec 12, 2006 6:43 am
Posts: 32
Location: London
hi,
just some thoughts

final DataStore data1 = new DataStore(data);

try to replace the above with

DataStore data1 = data

I am still did not get it why you create a DataStore from a DataStore?

Your code is trying to modify a primary key ( surrogate key ) which is not allowed.

Caused by: java.sql.SQLException: Attempt to modify an identity column 'ID'.

_________________
Alan Mehio
London
UK


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 16, 2008 7:27 am 
Beginner
Beginner

Joined: Tue Dec 12, 2006 6:43 am
Posts: 32
Location: London
hi,
just some thoughts

final DataStore data1 = new DataStore(data);

try to replace the above with

DataStore data1 = data

I am still did not get it why you create a DataStore from a DataStore?

Your code is trying to modify a primary key ( surrogate key ) which is not allowed.

Caused by: java.sql.SQLException: Attempt to modify an identity column 'ID'.

_________________
Alan Mehio
London
UK


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 6:24 am 
Newbie

Joined: Sun Jun 15, 2008 11:16 pm
Posts: 3
Location: philppines
alanmehio wrote:
hi,
just some thoughts

final DataStore data1 = new DataStore(data);

try to replace the above with

DataStore data1 = data

I am still did not get it why you create a DataStore from a DataStore?

Your code is trying to modify a primary key ( surrogate key ) which is not allowed.

Caused by: java.sql.SQLException: Attempt to modify an identity column 'ID'.


Hi,

My mistake I've already modify my code

public void populateData(DataStore data) {
try {
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
session.save(data);
session.getTransaction().commit();
} catch (HibernateException e) {
e.printStackTrace();
}

}

But still I can't understand why my code trying to modify the primary key when It was suppose to store a new persistent object w/o trying to modify it.

DataStore data = new DataStore();
data.setParent(2);
data.setData("data3");
data.setTypes("types3");

I can only retrieve the data that are already in the database, and what I'm trying to do is that my client can also populate my database then retrieve it Asynchronously, am I missing some configuration or anything?

Thank you very much.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 3:34 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
I'd be curious to see what happens if you use the saveOrUpdate method? Save won't work...Maybe it can update an existing record?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 18, 2008 9:02 pm 
Newbie

Joined: Sun Jun 15, 2008 11:16 pm
Posts: 3
Location: philppines
Cameron McKenzie wrote:
I'd be curious to see what happens if you use the saveOrUpdate method? Save won't work...Maybe it can update an existing record?


Hi,

It doesn't work either do you have any idea why new object attempt to modify my primary ID?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 18, 2008 9:10 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Has anyone implemented a custom hashcode or equals method? Maybe Hibernate thinks two objects that are not the same, actually are the same, and that is why it is giving this error.

Just an idea.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.