Note that there are some explanatory texts on larger screens.

plurals
  1. POMapping exception when using discriminator in Grails 2.0.0
    primarykey
    data
    text
    <p>At general I have problem with mapping: <code>org.hibernate.MappingException: Repeated column in mapping for entity: os.comida.StoreDocumentRw column: Type (should be mapped with insert="false" update="false")</code></p> <p>To introduce the problem: I have many document types where each document type differs just a little bit from any other. All of them have common properties: date, number, issuer etc. So I decided store all document types in one physical table (one - it's very important for me). To implement this I wanted use hibernate discriminator.</p> <p>Below I'm pasting my source code. I have there a base class <code>StoreDocument</code> and two document types <code>StoreDocumentRw</code> and <code>StoreDocumentWz</code>.</p> <pre><code>class StoreDocument { String type Date documentDate static mapping = { table '"StoreDocument"' version false id column:'"StoreDocumentID"', generator:'sequence', params:[sequence:'STORE_DOCUMENT_SEQ'] discriminator column: '"Type"' documentDate column:'"DocumentDate"' type column:'"Type"' } } class StoreDocumentRw extends StoreDocument { String rwSpecificData static mapping = { discriminator value: 'rw' rwSpecificData column:'"RwSpecificData"' } } class StoreDocumentWz extends StoreDocument { String wzSpecificData static mapping = { discriminator value: 'wz' wzSpecificData column:'"WzSpecificData"' } } </code></pre> <p>And when I'm trying run an app I get mentioned earlier <code>org.hibernate.MappingException: Repeated column in mapping for entity: os.comida.StoreDocumentRw column: Type (should be mapped with insert="false" update="false")</code></p> <p>When I add <code>type insertable: false, updateable: false</code> to <code>StoreDocumentRw</code> mapping, it's still the same. </p> <p>When I add <code>type insertable: false, updateable: false</code> to <code>StoreDocument</code> mapping, it's even worse:</p> <pre><code>ERROR hbm2ddl.SchemaExport - Unsuccessful: create table COMIDA2."StoreDocument" ("StoreDocumentID" number(19,0) not null, "DocumentDate" timestamp not null, "Type" varchar2(255 char), "Type" varchar2(-1 char) not null, "WzSpecificData" varchar2(255 char), "RwSpecificData" varchar2(255 char), primary key ("StoreDocumentID")) ERROR hbm2ddl.SchemaExport - ORA-00957: duplicate column name </code></pre> <p>So I don't know where I should put this insertable/updateable thing to make it working. I'm using Grails 2.0.0 and Oracle 10g. Can anybody tell me what's wrong with my code?</p> <hr> <h2>Solution:</h2> <p>My mapping in <code>StoreDocument</code> was wrong. It's enough to cut <code>String type</code> and <code>type column:'"Type"'</code> and edit discriminator mapping like this <code>discriminator column:[name:'"Type"',length:50]</code>, which in result gives:</p> <pre><code>class StoreDocument { Date documentDate static mapping = { table '"StoreDocument"' version false id column:'"StoreDocumentID"', generator:'sequence', params:[sequence:'STORE_DOCUMENT_SEQ'] discriminator column:[name:'"Type"',length:50] documentDate column:'"DocumentDate"' } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload