Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] Many-to-many association with SQLServer Database -> SQLServerException: Cannot insert t
[CDO] Many-to-many association with SQLServer Database -> SQLServerException: Cannot insert t [message #821724] Thu, 15 March 2012 18:38 Go to next message
Goetz Botterweck is currently offline Goetz BotterweckFriend
Messages: 71
Registered: July 2009
Member
WHAT I WANT TO DO

Have two classes (e.g., Book and Writer) with many-to-many association
between them.


PROBLEM

When trying to link two objects
... create writer1 and book1 ...
writer1.getBook().add(book1);
transaction.commit();

the program fails with
SQLServerException: Cannot insert the value NULL into column
book_bookname', table '<db>.dbo.book_writer'; column does not allow
nulls. INSERT fails.

We want to use Microsoft SQL Server as a database backend. It might very
well that MS-SQL behaves differently about NOT NULL constraints when
inserting new records.

I am pasting more detailed information below, including
- system info
- trace
- generated HBM
- metamodel of the example, Book *-------* Writer

Any hints would greatly be appreciated,
Goetz





SYSTEM INFO -----------------------------------

- CDO Model Repo 4.0.0
- EMF Teneo CDO 1.2.0
- Hibernate 3.6.0
- Microsoft SQLServer via Microsoft JDBC Driver 3.0


TRACE -----------------------------------

[ERROR] Rollback in HibernateStore:
org.hibernate.exception.ConstraintViolationException: could not insert
collection: [Writer.book#wA]
at
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)
at
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at
org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1243)
at
org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:58)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:188)
at
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at
org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreAccessor.doWrite(HibernateStoreAccessor.java:686)
at
org.eclipse.emf.cdo.spi.server.StoreAccessorBase.write(StoreAccessorBase.java:150)
at
org.eclipse.emf.cdo.internal.server.TransactionCommitContext.write(TransactionCommitContext.java:463)
at
org.eclipse.emf.cdo.spi.server.InternalCommitContext$1.runLoop(InternalCommitContext.java:42)
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:244)
at
org.eclipse.emf.cdo.server.internal.net4j.protocol.CommitTransactionIndication.indicating(CommitTransactionIndication.java:92)
at
org.eclipse.emf.cdo.server.internal.net4j.protocol.CDOServerIndicationWithMonitoring.indicating(CDOServerIndicationWithMonitoring.java:109)
at
org.eclipse.net4j.signal.IndicationWithMonitoring.indicating(IndicationWithMonitoring.java:84)
at
org.eclipse.net4j.signal.IndicationWithResponse.doExtendedInput(IndicationWithResponse.java:90)
at org.eclipse.net4j.signal.Signal.doInput(Signal.java:326)
at
org.eclipse.net4j.signal.IndicationWithResponse.execute(IndicationWithResponse.java:63)
at
org.eclipse.net4j.signal.IndicationWithMonitoring.execute(IndicationWithMonitoring.java:63)
at org.eclipse.net4j.signal.Signal.runSync(Signal.java:251)
at org.eclipse.net4j.signal.Signal.run(Signal.java:147)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot
insert the value NULL into column 'book_bookname', table
'db1.dbo.book_writer'; column does not allow nulls. INSERT
fails.
at
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
at
com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493)
at
com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:390)
at
com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
at
com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
at
com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
at
com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
at
com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(SQLServerPreparedStatement.java:308)
at
org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:46)
at
org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1206)
... 26 more

HBM ---------------------------------

<?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 auto-import="false">
<class entity-name="Writer" abstract="false" lazy="true" table="`writer`">
<meta attribute="eclassName" inherit="false">Writer</meta>
<meta attribute="epackage"
inherit="false">http://lero.ie/spl/demo/writerAndBook.ecore</meta>
<tuplizer entity-mode="pojo"
class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/>
<tuplizer entity-mode="dynamic-map"
class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/>
<id name="writerName" type="java.lang.String">
<column not-null="true" unique="false" name="`writername`"/>
</id>
<property name="resourceID"
type="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDUserType">
<column name="resource_id"/>
</property>
<property name="containerID" type="string">
<column name="container_id"/>
</property>
<property name="version" type="java.lang.Integer">
<meta attribute="version">true</meta>
<column name="version"/>
</property>
<property name="commit_TimeStamp" type="java.lang.Long"/>
<bag name="book" lazy="true"
cascade="merge,persist,save-update,lock" table="`book_writer`">
<key update="true">
<column name="`writer_writername`" unique="false"/>
</key>
<many-to-many entity-name="Book" unique="false"
foreign-key="writer_book">
<column name="`book_e_id`" not-null="true" unique="false"/>
</many-to-many>
</bag>
</class>
<class entity-name="Book" abstract="false" lazy="true" table="`book`">
<meta attribute="eclassName" inherit="false">Book</meta>
<meta attribute="epackage"
inherit="false">http://lero.ie/spl/demo/writerAndBook.ecore</meta>
<tuplizer entity-mode="pojo"
class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/>
<tuplizer entity-mode="dynamic-map"
class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/>
<id name="bookName" type="java.lang.String">
<column not-null="true" unique="false" name="`bookname`"/>
</id>
<property name="resourceID"
type="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDUserType">
<column name="resource_id"/>
</property>
<property name="containerID" type="string">
<column name="container_id"/>
</property>
<property name="version" type="java.lang.Integer">
<meta attribute="version">true</meta>
<column name="version"/>
</property>
<property name="commit_TimeStamp" type="java.lang.Long"/>
<bag name="writer" lazy="true"
cascade="merge,persist,save-update,lock" inverse="true"
table="`book_writer`">
<key update="true">
<column name="`book_bookname`" unique="false"/>
</key>
<many-to-many entity-name="Writer" unique="false"
foreign-key="book_writer">
<column name="`writer_writername`" not-null="true" unique="false"/>
</many-to-many>
</bag>
</class>
</hibernate-mapping>

METAMODEL ---------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="writerAndBook"
nsURI="http://lero.ie/spl/demo/writerAndBook.ecore" nsPrefix="wb">
<eClassifiers xsi:type="ecore:EClass" name="Writer">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="writerName"
ordered="false"
lowerBound="1" eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EString"
iD="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="book"
ordered="false" upperBound="-1"
eType="#//Book" eOpposite="#//Book/writer"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Book">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="bookName"
ordered="false"
lowerBound="1" eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EString"
iD="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="writer"
ordered="false"
upperBound="-1" eType="#//Writer" eOpposite="#//Writer/book"/>
</eClassifiers>
</ecore:EPackage>
Re: [CDO] Many-to-many association with SQLServer Database -&gt; SQLServerException: Cannot inse [message #821751 is a reply to message #821724] Thu, 15 March 2012 19:28 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Goetz,
The book has a title/name set?

gr. Martin

On 03/15/2012 07:38 PM, Goetz Botterweck wrote:
> WHAT I WANT TO DO
>
> Have two classes (e.g., Book and Writer) with many-to-many association
> between them.
>
>
> PROBLEM
>
> When trying to link two objects
> ... create writer1 and book1 ...
> writer1.getBook().add(book1);
> transaction.commit();
>
> the program fails with
> SQLServerException: Cannot insert the value NULL into column
> book_bookname', table '<db>.dbo.book_writer'; column does not allow
> nulls. INSERT fails.
>
> We want to use Microsoft SQL Server as a database backend. It might very
> well that MS-SQL behaves differently about NOT NULL constraints when
> inserting new records.
>
> I am pasting more detailed information below, including
> - system info
> - trace
> - generated HBM
> - metamodel of the example, Book *-------* Writer
>
> Any hints would greatly be appreciated,
> Goetz
>
>
>
>
>
> SYSTEM INFO -----------------------------------
>
> - CDO Model Repo 4.0.0
> - EMF Teneo CDO 1.2.0
> - Hibernate 3.6.0
> - Microsoft SQLServer via Microsoft JDBC Driver 3.0
>
>
> TRACE -----------------------------------
>
> [ERROR] Rollback in HibernateStore:
> org.hibernate.exception.ConstraintViolationException: could not insert
> collection: [Writer.book#wA]
> at
> org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)
> at
> org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
> at
> org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1243)
> at
> org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:58)
> at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
> at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
> at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:188)
> at
> org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
> at
> org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
> at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
> at
> org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreAccessor.doWrite(HibernateStoreAccessor.java:686)
> at
> org.eclipse.emf.cdo.spi.server.StoreAccessorBase.write(StoreAccessorBase.java:150)
> at
> org.eclipse.emf.cdo.internal.server.TransactionCommitContext.write(TransactionCommitContext.java:463)
> at
> org.eclipse.emf.cdo.spi.server.InternalCommitContext$1.runLoop(InternalCommitContext.java:42)
> 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:244)
> at
> org.eclipse.emf.cdo.server.internal.net4j.protocol.CommitTransactionIndication.indicating(CommitTransactionIndication.java:92)
> at
> org.eclipse.emf.cdo.server.internal.net4j.protocol.CDOServerIndicationWithMonitoring.indicating(CDOServerIndicationWithMonitoring.java:109)
> at
> org.eclipse.net4j.signal.IndicationWithMonitoring.indicating(IndicationWithMonitoring.java:84)
> at
> org.eclipse.net4j.signal.IndicationWithResponse.doExtendedInput(IndicationWithResponse.java:90)
> at org.eclipse.net4j.signal.Signal.doInput(Signal.java:326)
> at
> org.eclipse.net4j.signal.IndicationWithResponse.execute(IndicationWithResponse.java:63)
> at
> org.eclipse.net4j.signal.IndicationWithMonitoring.execute(IndicationWithMonitoring.java:63)
> at org.eclipse.net4j.signal.Signal.runSync(Signal.java:251)
> at org.eclipse.net4j.signal.Signal.run(Signal.java:147)
> at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
> at java.lang.Thread.run(Unknown Source)
> Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot
> insert the value NULL into column 'book_bookname', table
> 'db1.dbo.book_writer'; column does not allow nulls. INSERT
> fails.
> at
> com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
> at
> com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493)
> at
> com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:390)
> at
> com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)
> at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
> at
> com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
> at
> com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
> at
> com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
> at
> com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(SQLServerPreparedStatement.java:308)
> at
> org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:46)
> at
> org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1206)
> ... 26 more
>
> HBM ---------------------------------
>
> <?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 auto-import="false">
> <class entity-name="Writer" abstract="false" lazy="true" table="`writer`">
> <meta attribute="eclassName" inherit="false">Writer</meta>
> <meta attribute="epackage"
> inherit="false">http://lero.ie/spl/demo/writerAndBook.ecore</meta>
> <tuplizer entity-mode="pojo"
> class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/>
> <tuplizer entity-mode="dynamic-map"
> class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/>
> <id name="writerName" type="java.lang.String">
> <column not-null="true" unique="false" name="`writername`"/>
> </id>
> <property name="resourceID"
> type="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDUserType">
> <column name="resource_id"/>
> </property>
> <property name="containerID" type="string">
> <column name="container_id"/>
> </property>
> <property name="version" type="java.lang.Integer">
> <meta attribute="version">true</meta>
> <column name="version"/>
> </property>
> <property name="commit_TimeStamp" type="java.lang.Long"/>
> <bag name="book" lazy="true"
> cascade="merge,persist,save-update,lock" table="`book_writer`">
> <key update="true">
> <column name="`writer_writername`" unique="false"/>
> </key>
> <many-to-many entity-name="Book" unique="false"
> foreign-key="writer_book">
> <column name="`book_e_id`" not-null="true" unique="false"/>
> </many-to-many>
> </bag>
> </class>
> <class entity-name="Book" abstract="false" lazy="true" table="`book`">
> <meta attribute="eclassName" inherit="false">Book</meta>
> <meta attribute="epackage"
> inherit="false">http://lero.ie/spl/demo/writerAndBook.ecore</meta>
> <tuplizer entity-mode="pojo"
> class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/>
> <tuplizer entity-mode="dynamic-map"
> class="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDORevisionTuplizer"/>
> <id name="bookName" type="java.lang.String">
> <column not-null="true" unique="false" name="`bookname`"/>
> </id>
> <property name="resourceID"
> type="org.eclipse.emf.cdo.server.internal.hibernate.tuplizer.CDOIDUserType">
> <column name="resource_id"/>
> </property>
> <property name="containerID" type="string">
> <column name="container_id"/>
> </property>
> <property name="version" type="java.lang.Integer">
> <meta attribute="version">true</meta>
> <column name="version"/>
> </property>
> <property name="commit_TimeStamp" type="java.lang.Long"/>
> <bag name="writer" lazy="true"
> cascade="merge,persist,save-update,lock" inverse="true"
> table="`book_writer`">
> <key update="true">
> <column name="`book_bookname`" unique="false"/>
> </key>
> <many-to-many entity-name="Writer" unique="false"
> foreign-key="book_writer">
> <column name="`writer_writername`" not-null="true" unique="false"/>
> </many-to-many>
> </bag>
> </class>
> </hibernate-mapping>
>
> METAMODEL ---------------------------------
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="writerAndBook"
> nsURI="http://lero.ie/spl/demo/writerAndBook.ecore" nsPrefix="wb">
> <eClassifiers xsi:type="ecore:EClass" name="Writer">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="writerName"
> ordered="false"
> lowerBound="1" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"
> iD="true"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="book"
> ordered="false" upperBound="-1"
> eType="#//Book" eOpposite="#//Book/writer"/>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Book">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="bookName"
> ordered="false"
> lowerBound="1" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"
> iD="true"/>
> <eStructuralFeatures xsi:type="ecore:EReference" name="writer"
> ordered="false"
> upperBound="-1" eType="#//Writer" eOpposite="#//Writer/book"/>
> </eClassifiers>
> </ecore:EPackage>
>
>


--

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@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [CDO] Many-to-many association with SQLServer Database -&gt; SQLServerException: Cannot inse [message #821771 is a reply to message #821751] Thu, 15 March 2012 19:59 Go to previous messageGo to next message
Goetz Botterweck is currently offline Goetz BotterweckFriend
Messages: 71
Registered: July 2009
Member
On 15/03/2012 19:28, Martin Taal wrote:
> Hi Goetz,
> The book has a title/name set?
Yes.

I will paste the little test that we created below. Also an SQL query
for creating the particular table, which I get from when doing "Script
Table As -> Create To" in SQL Server Management Studio.


--- Test ----------------------------

package com.tutorial.cdo.hibernate.client;

import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.transaction.CDOTransaction;

import writerAndBook.Book;
import writerAndBook.Writer;
import writerAndBook.WriterAndBookFactory;

public class QuickStartTest extends BaseTest
{

@SuppressWarnings("unchecked")
public void testCreatePersist() throws Exception
{
{
final CDOSession session = openSession();
final CDOTransaction transaction = session.openTransaction();

//create writers
final Writer writer1= WriterAndBookFactory.eINSTANCE.createWriter();
final Writer writer2 = WriterAndBookFactory.eINSTANCE.createWriter();
final Writer writer3 = WriterAndBookFactory.eINSTANCE.createWriter();


//create books
final Book book1 = WriterAndBookFactory.eINSTANCE.createBook();
final Book book2 = WriterAndBookFactory.eINSTANCE.createBook();
final Book book3 = WriterAndBookFactory.eINSTANCE.createBook();

//get/create a resource
CDOResource resource =
transaction.getOrCreateResource("/resWriterAndBooks"); //$NON-NLS-1$

//clear any previous data
resource.getContents().clear();

//start creating new data
writer1.setWriterName("wA");
writer2.setWriterName("wB");
writer3.setWriterName("wC");

book1.setBookName("bA");
book2.setBookName("bB");
book3.setBookName("bC");


writer1.getBook().add(book1);
writer2.getBook().add(book2);
writer3.getBook().add(book3);


writer1.getBook().add(book2);
writer2.getBook().add(book1);

resource.getContents().add(writer1);
resource.getContents().add(writer2);
resource.getContents().add(writer3);


resource.getContents().add(book1);
resource.getContents().add(book2);
resource.getContents().add(book3);

transaction.commit();
}
}
}


--- SQL Script for Table ----------------------------

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[book_writer](
[writer_writername] [varchar](255) NOT NULL,
[book_e_id] [varchar](255) NOT NULL,
[book_bookname] [varchar](255) NOT NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[book_writer] WITH CHECK ADD CONSTRAINT
[FK1326FE89CB17F493] FOREIGN KEY([book_bookname])
REFERENCES [dbo].[book] ([bookname])
GO

ALTER TABLE [dbo].[book_writer] CHECK CONSTRAINT [FK1326FE89CB17F493]
GO

ALTER TABLE [dbo].[book_writer] WITH CHECK ADD CONSTRAINT
[writer_book] FOREIGN KEY([book_e_id])
REFERENCES [dbo].[book] ([bookname])
GO

ALTER TABLE [dbo].[book_writer] CHECK CONSTRAINT [writer_book]
GO
Re: [CDO] Many-to-many association with SQLServer Database -&gt; SQLServerException: Cannot inse [message #822065 is a reply to message #821771] Fri, 16 March 2012 05:56 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Goetz,
I see what happens the column names for the book in the join table are there twice, once for each direction. There is
both a book_e_id (for the reference from writer to book) and book_bookname (for the reference from book to writer).

When inserting one direction, hibernate ignores the book_bookname column which is mandatory and throws an error.

The reason for this mapping error is that the id feature of the book is not recognized during the mapping of the
many-to-many. It ignores the iD=true on the eAttribute. Therefore the book_e_id is created, while it should use the
book_bookname.

Can you try if adding the @Id annotation to the bookName eAttribute helps?

gr. Martin

On 03/15/2012 08:59 PM, Goetz Botterweck wrote:
> On 15/03/2012 19:28, Martin Taal wrote:
>> Hi Goetz,
>> The book has a title/name set?
> Yes.
>
> I will paste the little test that we created below. Also an SQL query
> for creating the particular table, which I get from when doing "Script
> Table As -> Create To" in SQL Server Management Studio.
>
>
> --- Test ----------------------------
>
> package com.tutorial.cdo.hibernate.client;
>
> import org.eclipse.emf.cdo.eresource.CDOResource;
> import org.eclipse.emf.cdo.session.CDOSession;
> import org.eclipse.emf.cdo.transaction.CDOTransaction;
>
> import writerAndBook.Book;
> import writerAndBook.Writer;
> import writerAndBook.WriterAndBookFactory;
>
> public class QuickStartTest extends BaseTest
> {
>
> @SuppressWarnings("unchecked")
> public void testCreatePersist() throws Exception
> {
> {
> final CDOSession session = openSession();
> final CDOTransaction transaction = session.openTransaction();
>
> //create writers
> final Writer writer1= WriterAndBookFactory.eINSTANCE.createWriter();
> final Writer writer2 = WriterAndBookFactory.eINSTANCE.createWriter();
> final Writer writer3 = WriterAndBookFactory.eINSTANCE.createWriter();
>
>
> //create books
> final Book book1 = WriterAndBookFactory.eINSTANCE.createBook();
> final Book book2 = WriterAndBookFactory.eINSTANCE.createBook();
> final Book book3 = WriterAndBookFactory.eINSTANCE.createBook();
>
> //get/create a resource
> CDOResource resource =
> transaction.getOrCreateResource("/resWriterAndBooks"); //$NON-NLS-1$
>
> //clear any previous data
> resource.getContents().clear();
>
> //start creating new data
> writer1.setWriterName("wA");
> writer2.setWriterName("wB");
> writer3.setWriterName("wC");
>
> book1.setBookName("bA");
> book2.setBookName("bB");
> book3.setBookName("bC");
>
>
> writer1.getBook().add(book1);
> writer2.getBook().add(book2);
> writer3.getBook().add(book3);
>
>
> writer1.getBook().add(book2);
> writer2.getBook().add(book1);
>
> resource.getContents().add(writer1);
> resource.getContents().add(writer2);
> resource.getContents().add(writer3);
>
>
> resource.getContents().add(book1);
> resource.getContents().add(book2);
> resource.getContents().add(book3);
>
> transaction.commit();
> }
> }
> }
>
>
> --- SQL Script for Table ----------------------------
>
> SET ANSI_NULLS ON
> GO
>
> SET QUOTED_IDENTIFIER ON
> GO
>
> SET ANSI_PADDING ON
> GO
>
> CREATE TABLE [dbo].[book_writer](
> [writer_writername] [varchar](255) NOT NULL,
> [book_e_id] [varchar](255) NOT NULL,
> [book_bookname] [varchar](255) NOT NULL
> ) ON [PRIMARY]
>
> GO
>
> SET ANSI_PADDING OFF
> GO
>
> ALTER TABLE [dbo].[book_writer] WITH CHECK ADD CONSTRAINT
> [FK1326FE89CB17F493] FOREIGN KEY([book_bookname])
> REFERENCES [dbo].[book] ([bookname])
> GO
>
> ALTER TABLE [dbo].[book_writer] CHECK CONSTRAINT [FK1326FE89CB17F493]
> GO
>
> ALTER TABLE [dbo].[book_writer] WITH CHECK ADD CONSTRAINT
> [writer_book] FOREIGN KEY([book_e_id])
> REFERENCES [dbo].[book] ([bookname])
> GO
>
> ALTER TABLE [dbo].[book_writer] CHECK CONSTRAINT [writer_book]
> GO
>


--

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@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: [CDO] Many-to-many association with SQLServer Database -&gt; SQLServerException: Cannot inse [message #822554 is a reply to message #822065] Fri, 16 March 2012 23:45 Go to previous messageGo to next message
Goetz Botterweck is currently offline Goetz BotterweckFriend
Messages: 71
Registered: July 2009
Member
On 16/03/2012 05:56, Martin Taal wrote:

> When inserting one direction, hibernate ignores the book_bookname column
> which is mandatory and throws an error.
>
> The reason for this mapping error is that the id feature of the book is
> not recognized during the mapping of the many-to-many. It ignores the
> iD=true on the eAttribute. Therefore the book_e_id is created, while it
> should use the book_bookname.
>
> Can you try if adding the @Id annotation to the bookName eAttribute helps?

Yes, that helped. Thanks!

Just out of interest, is there a particular reason why hibernate ignores
the iD=true annotation?
Re: [CDO] Many-to-many association with SQLServer Database -&gt; SQLServerException: Cannot inse [message #822971 is a reply to message #822554] Sat, 17 March 2012 15:25 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
It is a bug in this specific case, it is not ignored for generating the id mapping itself, so only for the join table it
goes wrong.

Can you enter a bugzilla on Teneo for this?

gr. Martin

On 03/17/2012 12:45 AM, Goetz Botterweck wrote:
> On 16/03/2012 05:56, Martin Taal wrote:
>
>> When inserting one direction, hibernate ignores the book_bookname column
>> which is mandatory and throws an error.
>>
>> The reason for this mapping error is that the id feature of the book is
>> not recognized during the mapping of the many-to-many. It ignores the
>> iD=true on the eAttribute. Therefore the book_e_id is created, while it
>> should use the book_bookname.
>>
>> Can you try if adding the @Id annotation to the bookName eAttribute helps?
>
> Yes, that helped. Thanks!
>
> Just out of interest, is there a particular reason why hibernate ignores
> the iD=true annotation?
>
>


--

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: [CDO] Many-to-many association with SQLServer Database -&gt; SQLServerException: Cannot inse [message #824176 is a reply to message #822971] Mon, 19 March 2012 10:54 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
I could not stop myself, I entered an issue and pushed a new solution and published a new build with this fix:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=374635

Can you try the latest teneo build?

gr. Martin

On 03/17/2012 04:25 PM, Martin Taal wrote:
> It is a bug in this specific case, it is not ignored for generating the id mapping itself, so only for the join table it
> goes wrong.
>
> Can you enter a bugzilla on Teneo for this?
>
> gr. Martin
>
> On 03/17/2012 12:45 AM, Goetz Botterweck wrote:
>> On 16/03/2012 05:56, Martin Taal wrote:
>>
>>> When inserting one direction, hibernate ignores the book_bookname column
>>> which is mandatory and throws an error.
>>>
>>> The reason for this mapping error is that the id feature of the book is
>>> not recognized during the mapping of the many-to-many. It ignores the
>>> iD=true on the eAttribute. Therefore the book_e_id is created, while it
>>> should use the book_bookname.
>>>
>>> Can you try if adding the @Id annotation to the bookName eAttribute helps?
>>
>> Yes, that helped. Thanks!
>>
>> Just out of interest, is there a particular reason why hibernate ignores
>> the iD=true annotation?
>>
>>
>
>


--

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
Previous Topic:Handling future model changes
Next Topic:Object Selection is empty
Goto Forum:
  


Current Time: Thu Mar 28 15:54:34 GMT 2024

Powered by FUDForum. Page generated in 0.03133 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top