Clear a resource with not null constraints [message #912602] |
Thu, 13 September 2012 20:48 |
Mark Rowe Messages: 23 Registered: January 2012 |
Junior Member |
|
|
Hello again list!
Details: Eclipse Juno, CDO 4.1, Hibernate/Teneo store, h2 database.
Apologies for incorrect terminology (please correct me though so I learn )
I am trying a model which is like this:
PersonClass
Name : EString StarSignClass
Sign : StarSignClass 1 ----> Name : Estring
The "Sign" column is being created in the PersonClass table with a NOT NULL.
When I issue
resource.getContents().clear()
I get a h2 exception because the framework is trying to run an update query with NULL in the "Sign" column.
If I add an EOpposite 0..* then everything is fine.
How can I clear the resource without adding the EOpposite relation?
Many thanks!
Edit: I just realised this might be a Hibernate/Teneo issue so apologies if posted in the wrong place.
[Updated on: Thu, 13 September 2012 21:37] Report message to a moderator
|
|
|
|
|
Re: Clear a resource with not null constraints [message #912908 is a reply to message #912786] |
Fri, 14 September 2012 11:34 |
|
Hi Mark,
When you said "h2 database" I thought you were referring to the DBStore with an H2Adapter. But now it seems as if you're
using the HibernateStore. I'm not an export for it but to me it seems as if the Teneo-created mapping is not correct. I
hope that Martin (cc'ed) can deduce something from your stack trace...
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Am 14.09.2012 09:26, schrieb Mark Rowe:
> Hi Eike, thank you again for your help!
>
> I have realised that my model is slightly different from the one I originally posted, its actually like this:
>
>
> MyObject <---------------------
> Name : EString |
> ^ |
> | |
> | |
> PersonClass |
> Ref : EString |
> Sign : StarSignClass 1 ----> StarSignClass
>
>
>
> Where both PersonClass and StarSignClass are inherited from MyObject.
>
> The exception is:
>
> Exception in thread "main" org.eclipse.emf.cdo.util.CommitException: Rollback in HibernateStore:
> org.hibernate.exception.ConstraintViolationException: NULL not allowed for column "starsignclass_sign_e_id"; SQL
> statement:
> update "personclass" set "starsignclass_sign_e_id"=?, ref=? where "myobject_e_id"=? [23502-168]
> at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:128)
> at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
> at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
> at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
> at
> org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
> at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
> at $Proxy5.executeUpdate(Unknown Source)
> at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3018)
> at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2916)
> at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3245)
> at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:113)
> at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
> at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354)
> at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:276)
> at
> org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326)
> at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
> at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1127)
> at org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreAccessor.doWrite(HibernateStoreAccessor.java:721)
> at org.eclipse.emf.cdo.spi.server.StoreAccessorBase.write(StoreAccessorBase.java:149)
> at org.eclipse.emf.cdo.internal.server.TransactionCommitContext.write(TransactionCommitContext.java:487)
> at org.eclipse.emf.cdo.spi.server.InternalCommitContext$1.runLoop(InternalCommitContext.java:43)
> at org.eclipse.emf.cdo.spi.server.InternalCommitContext$1.runLoop(InternalCommitContext.java:1)
> at org.eclipse.net4j.util.om.monitor.ProgressDistributor.run(ProgressDistributor.java:96)
> at
> org.eclipse.emf.cdo.server.internal.net4j.protocol.CommitTransactionIndication.indicatingCommit(CommitTransactionIndication.java:262)
> at
> org.eclipse.emf.cdo.server.internal.net4j.protocol.CommitTransactionIndication.indicating(CommitTransactionIndication.java:96)
> at
> org.eclipse.emf.cdo.server.internal.net4j.protocol.CDOServerIndicationWithMonitoring.indicating(CDOServerIndicationWithMonitoring.java:109)
> at org.eclipse.net4j.signal.IndicationWithMonitoring.indicating(IndicationWithMonitoring.java:86)
> at org.eclipse.net4j.signal.IndicationWithResponse.doExtendedInput(IndicationWithResponse.java:92)
> at org.eclipse.net4j.signal.Signal.doInput(Signal.java:328)
> at org.eclipse.net4j.signal.IndicationWithResponse.execute(IndicationWithResponse.java:65)
> at org.eclipse.net4j.signal.IndicationWithMonitoring.execute(IndicationWithMonitoring.java:65)
> at org.eclipse.net4j.signal.Signal.runSync(Signal.java:253)
> at org.eclipse.net4j.signal.Signal.run(Signal.java:149)
> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
> at java.lang.Thread.run(Thread.java:662)
> Caused by: org.h2.jdbc.JdbcSQLException: NULL not allowed for column "starsignclass_sign_e_id"; SQL statement:
> update "personclass" set "starsignclass_sign_e_id"=?, ref=? where "myobject_e_id"=? [23502-168]
> at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
> at org.h2.message.DbException.get(DbException.java:169)
> at org.h2.message.DbException.get(DbException.java:146)
> at org.h2.table.Column.validateConvertUpdateSequence(Column.java:293)
> at org.h2.table.Table.validateConvertUpdateSequence(Table.java:689)
> at org.h2.command.dml.Update.update(Update.java:123)
> at org.h2.command.CommandContainer.update(CommandContainer.java:75)
> at org.h2.command.Command.executeUpdate(Command.java:230)
> at org.h2.server.TcpServerThread.process(TcpServerThread.java:328)
> at org.h2.server.TcpServerThread.run(TcpServerThread.java:149)
> at java.lang.Thread.run(Thread.java:722)
>
> at org.h2.engine.SessionRemote.done(SessionRemote.java:567)
> at org.h2.command.CommandRemote.executeUpdate(CommandRemote.java:183)
> at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:156)
> at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:142)
> at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
> ... 31 more
>
> at
> org.eclipse.emf.internal.cdo.transaction.CDOSingleTransactionStrategyImpl.commit(CDOSingleTransactionStrategyImpl.java:85)
> at org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl.commit(CDOTransactionImpl.java:1134)
> at org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl.commit(CDOTransactionImpl.java:1154)
> at org.eclipse.emf.cdo.examples.hibernate.client.learning.<init>(test.java:47)
> at org.eclipse.emf.cdo.examples.hibernate.client.learning.main(test.java:137)
>
> Please note, I have edited the names in this exception trace because I don't have that person model running at the
> moment.
>
> What I guess is happening is that
> resource.getContents().clear();
>
> Is first inserting NULL into all foreign key fields so it can delete the related records without causing relational
> integrity errors. It works well in the Company example because there is an EOpposite "orderDetails (0..*)" which means
> Order.order is nullable.
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
|
Re: Clear a resource with not null constraints [message #913035 is a reply to message #912909] |
Fri, 14 September 2012 16:38 |
Mark Rowe Messages: 23 Registered: January 2012 |
Junior Member |
|
|
Yes, you are right! I forgot to include Hibernate/Teneo in my original post. I added it a few minutes later but you had already answered!
For reference I have tried the same model / client with the DBStore (and h2) and it works perfectly.
I don't know if this is relevant but in the example cdo-server.xml for Hibernate/Teneo it says this:
<!-- The following value must be set normally like this, use this in your app also -->
<property name="teneo.mapping.cascade_policy_on_non_containment" value="PERSIST,MERGE"/>
I take the "...use this in your app also" to mean use it in your server also or should I be adding something in the client?
[Updated on: Fri, 14 September 2012 16:43] Report message to a moderator
|
|
|
Re: Clear a resource with not null constraints [message #913293 is a reply to message #912786] |
Sat, 15 September 2012 07:00 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Mark,
Indeed this can happen, to be sure can you try with making the StarSignClass association optional?
I am thinking of adding a configuration option to make the columns of these non-optional many-to-one nullable. So the
assocation in the mapping it will be not-optional but its database schema element (the column) will be nullable.
gr. Martin
On 09/14/2012 09:26 AM, Mark Rowe wrote:
> Hi Eike, thank you again for your help!
>
> I have realised that my model is slightly different from the one I originally posted, its actually like this:
>
>
> MyObject <---------------------
> Name : EString |
> ^ |
> | |
> | |
> PersonClass |
> Ref : EString |
> Sign : StarSignClass 1 ----> StarSignClass
>
>
>
> Where both PersonClass and StarSignClass are inherited from MyObject.
>
> The exception is:
>
> Exception in thread "main" org.eclipse.emf.cdo.util.CommitException: Rollback in HibernateStore:
> org.hibernate.exception.ConstraintViolationException: NULL not allowed for column "starsignclass_sign_e_id"; SQL statement:
> update "personclass" set "starsignclass_sign_e_id"=?, ref=? where "myobject_e_id"=? [23502-168]
> at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:128)
> at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
> at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
> at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
> at
> org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
>
> at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
> at $Proxy5.executeUpdate(Unknown Source)
> at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3018)
> at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2916)
> at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3245)
> at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:113)
> at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
> at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354)
> at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:276)
> at
> org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326)
> at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
> at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1127)
> at org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreAccessor.doWrite(HibernateStoreAccessor.java:721)
> at org.eclipse.emf.cdo.spi.server.StoreAccessorBase.write(StoreAccessorBase.java:149)
> at org.eclipse.emf.cdo.internal.server.TransactionCommitContext.write(TransactionCommitContext.java:487)
> at org.eclipse.emf.cdo.spi.server.InternalCommitContext$1.runLoop(InternalCommitContext.java:43)
> at org.eclipse.emf.cdo.spi.server.InternalCommitContext$1.runLoop(InternalCommitContext.java:1)
> at org.eclipse.net4j.util.om.monitor.ProgressDistributor.run(ProgressDistributor.java:96)
> at
> org.eclipse.emf.cdo.server.internal.net4j.protocol.CommitTransactionIndication.indicatingCommit(CommitTransactionIndication.java:262)
>
> at
> org.eclipse.emf.cdo.server.internal.net4j.protocol.CommitTransactionIndication.indicating(CommitTransactionIndication.java:96)
>
> at
> org.eclipse.emf.cdo.server.internal.net4j.protocol.CDOServerIndicationWithMonitoring.indicating(CDOServerIndicationWithMonitoring.java:109)
>
> at org.eclipse.net4j.signal.IndicationWithMonitoring.indicating(IndicationWithMonitoring.java:86)
> at org.eclipse.net4j.signal.IndicationWithResponse.doExtendedInput(IndicationWithResponse.java:92)
> at org.eclipse.net4j.signal.Signal.doInput(Signal.java:328)
> at org.eclipse.net4j.signal.IndicationWithResponse.execute(IndicationWithResponse.java:65)
> at org.eclipse.net4j.signal.IndicationWithMonitoring.execute(IndicationWithMonitoring.java:65)
> at org.eclipse.net4j.signal.Signal.runSync(Signal.java:253)
> at org.eclipse.net4j.signal.Signal.run(Signal.java:149)
> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
> at java.lang.Thread.run(Thread.java:662)
> Caused by: org.h2.jdbc.JdbcSQLException: NULL not allowed for column "starsignclass_sign_e_id"; SQL statement:
> update "personclass" set "starsignclass_sign_e_id"=?, ref=? where "myobject_e_id"=? [23502-168]
> at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
> at org.h2.message.DbException.get(DbException.java:169)
> at org.h2.message.DbException.get(DbException.java:146)
> at org.h2.table.Column.validateConvertUpdateSequence(Column.java:293)
> at org.h2.table.Table.validateConvertUpdateSequence(Table.java:689)
> at org.h2.command.dml.Update.update(Update.java:123)
> at org.h2.command.CommandContainer.update(CommandContainer.java:75)
> at org.h2.command.Command.executeUpdate(Command.java:230)
> at org.h2.server.TcpServerThread.process(TcpServerThread.java:328)
> at org.h2.server.TcpServerThread.run(TcpServerThread.java:149)
> at java.lang.Thread.run(Thread.java:722)
>
> at org.h2.engine.SessionRemote.done(SessionRemote.java:567)
> at org.h2.command.CommandRemote.executeUpdate(CommandRemote.java:183)
> at org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:156)
> at org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:142)
> at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
>
> ... 31 more
>
> at
> org.eclipse.emf.internal.cdo.transaction.CDOSingleTransactionStrategyImpl.commit(CDOSingleTransactionStrategyImpl.java:85)
> at org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl.commit(CDOTransactionImpl.java:1134)
> at org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl.commit(CDOTransactionImpl.java:1154)
> at org.eclipse.emf.cdo.examples.hibernate.client.learning.<init>(test.java:47)
> at org.eclipse.emf.cdo.examples.hibernate.client.learning.main(test.java:137)
>
> Please note, I have edited the names in this exception trace because I don't have that person model running at the moment.
>
> What I guess is happening is that
> resource.getContents().clear();
>
> Is first inserting NULL into all foreign key fields so it can delete the related records without causing relational
> integrity errors. It works well in the Company example because there is an EOpposite "orderDetails (0..*)" which means
> Order.order is nullable.
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
|
|
|
Re: Clear a resource with not null constraints [message #913476 is a reply to message #913293] |
Sat, 15 September 2012 18:59 |
Mark Rowe Messages: 23 Registered: January 2012 |
Junior Member |
|
|
Hi Martin,
Thanks for your help and looking into this.
Yes, if I change the mapping to 0..1 then the column is nullable (as you would expect) and my client works. Of course this looses a degree of referential integrity.
What you suggest seems to be sensible because at the moment the database rules are getting in the way of the model. Out of interest it seems that DB store makes one-to-one relationships nullable.
Ideally (but probably not possible) it would be better to create a temporary instance of the referenced class, point to that until the referring class is deleted.
tkr, Mark
[Updated on: Sat, 15 September 2012 20:52] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03879 seconds