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.  [ 1 post ] 
Author Message
 Post subject: Problems with Mapping of a collection
PostPosted: Fri Aug 29, 2008 11:02 am 
Newbie

Joined: Fri Aug 29, 2008 10:17 am
Posts: 1
NHibernate version:
1.2.1.4000


A little bit SQL (Oracle):
Code:
create table PARAMETER (
  ID                    INTEGER         NOT NULL,
  NAME                  VARCHAR2 (12)   NOT NULL,
  ROW_VERSION           INTEGER         NOT NULL,

  // ...

  constraint PARAMETER_PK primary key (ID)
);


create table PARAMETER_SET (
  ID                    INTEGER         NOT NULL, 
  // -- KEY via INDEX --
  REQUEST_ID              VARCHAR2 (10)   NOT NULL,
  TRANSACTION           VARCHAR2 (10)    NOT NULL,
  PARAMETER_ID          INTEGER         NOT NULL,
  // ---------
  ROW_VERSION           INTEGER         NOT NULL,
 
  // ...
 
  constraint PARAMETER_SET_PK primary key (ID)
);

create table REQUEST (
  ID                    VARCHAR2 (10)   NOT NULL,
  ROW_VERSION           INTEGER         NOT NULL,
 
  // ...
 
  constraint REQUEST_PK primary key (ID)
);

// a unique index on the real key for ParameterSet
create unique index PARAMETER_SET_UI1 on PARAMETER_SET (
    REQUEST_ID,
    TRANSACTION,
    PARAMETER_ID
);



Mapping documents:

Code:
<class name="Request, Domain"
         table="REQUEST" lazy="false">

    <id name="ID" column="ID">
      <generator class="native">
        <param name="sequence">REQUEST_SEQ</param>
      </generator>
    </id>   

    <version name="RowVersion" column="ROW_VERSION" type="Int32" unsaved-value="0" />

    <property name="Name"             column="NAME" />

    <bag name   ="ParameterSets"
         inverse ="true"
         cascade ="all-delete-orphan"
         lazy    ="false">
      <key column="REQUEST_ID"/>
      <one-to-many class="ParameterSet, Domain"/>
    </bag>
</class>



<class name="ParameterSet, Domain"
         table="PARAMETER_SET" lazy="false">

    <id name="ID" column="ID">
      <generator class="native">
        <param name="sequence">PARAM_SET_SEQ</param>
      </generator>
    </id>
   
    <version name="RowVersion" column="ROW_VERSION" type="Int32" unsaved-value="0" />

    <property name="Transaction" column="TRANSACTION">
      <column name="TRANSACTION" unique-key="TEST" index="PARAMETER_SET_UI1"/>
    </property>

    <property name="Target"         column="TARGET" />

    <many-to-one name="Request" column="REQUEST_ID"
              class="Request, Domain"
              not-null="false"
              lazy="false"
              insert="true" update="false">
      <column name="REQUEST_ID" unique-key="TEST" index="PARAMETER_SET_UI1"/>
    </many-to-one>

    <many-to-one name="Parameter" column="PARAMETER_ID"
              class="Parameter, Domain"
              not-null="false"
              lazy="false"
              insert="true" update="false">
      <column name="PARAMETER_ID" unique-key="TEST" index="PARAMETER_SET_UI1"/>
    </many-to-one>

</class>



<class name="Parameter, Domain" table="PARAMETER">

    <id name="ID" column="ID">
      <generator class="assigned" />
    </id>

    <version name="RowVersion" column="ROW_VERSION" type="Int32" unsaved-value="0" />

    <property name="Name"             column="NAME" />
</class>



Code that makes some problems:

Code:
Request request = // Load a request

// The ParameterSets of the Reuqest contains an object with
//    Transaction = "T1"
//    Reuqest      = request
//    Parameter   = Parameter (PARAM1)
request.ParameterSets.Clear();

ParameterSet ps = new ParameterSet();
// A part of the data of the new ParameterSet is set to:
//    Transaction = "T1"
//    Reuqest      = request
//    Parameter   = Parameter (PARAM1)

request.ParameterSets.Add(ps);

// The Error is thrown here:
HibernateSession.SaveOrUpdate(request);

// The problem is, on the Database must be an unique index on the columns Transaction, Request_ID and Parameter_ID to allow only one unique object with this combination.


The Error:
Code:
Hibernate flusing: could not insert: [Domain.ParameterSet#2538][SQL: INSERT INTO PARAMETER_SET (ROW_VERSION, TRANSACTION, MODIFICATION, SEQUENCE_NUMBER, TARGET, LOWER_SPEC_LIMIT, UPPER_SPEC_LIMIT, STOP_FLAG, OPTIONAL_FLAG, REQUEST_ID, PARAMETER_ID, ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; SQL []; ORA-00001: Verstoß gegen Eindeutigkeit, Regel (DBXYZ.PARAMETER_SET_UI1)


Name and version of the database you are using:
ORACLE 9i


Problems (Description):

I remove and add new objects at one step to the collection (ParameterSets). There are no objects left in the collection that tresspass against the INDEX on the database. But it seams, that NHibernate inserts the new objects of the collection first, before it deletes the removed elements from database at SaveOrUpdate(...).

Have anyone an idea, how I can modify the mapping, that NHibernate works with the database-INDEX?

Mike


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

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.