-->
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: Generation of SQL insert statement
PostPosted: Mon Mar 07, 2011 10:54 am 
Newbie

Joined: Fri Feb 18, 2011 5:23 am
Posts: 2
Hi,

I'm using a SQL DB and when trying to create a driver with address information I get an error that tells me this:

Quote:
Cannot insert explicit value for identity column in table 'DRIVERADDRESSES' when IDENTITY_INSERT is set to OFF.


DRIVERADDRESSES is an intermediate class.

The mapping looks like this:

Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping default-cascade="none" xmlns="urn:nhibernate-mapping-2.2"
        namespace="Address" assembly="Domain">

  <class name="DriverAddresses" table="DriverAddresses">

    <id name="DriverAddressID" column="DRIVERADDRESSESID" type="Int32">
      <generator class="id_generator_Int32"/>
    </id>

    <property name="PersonID" column="PERSONID" type="Int32" not-null="true"/>
    <property name="TnrId" column="TNRID" type="Int32" not-null="true"/>
    <property name="ValidFrom" column="VALIDFROM" type="DateTime" not-null="true"/>
    <property name="ValidTo" column="VALIDTO" type="DateTime" not-null="false"/>

    <many-to-one name="Address" class="Address" column="ADDRESSID"
                 not-found="ignore" not-null="false" unique="true" cascade="save-update"
                 lazy="false" outer-join="true"/>
  </class>
</hibernate-mapping>


The SQL being generated for the SQL statement is the following:
Code:
INSERT INTO DRIVERADDRESSES (PERSONID, TNRID, VALIDFROM, VALIDTO, ADDRESSID, DRIVERADDRESSESID) VALUES (@p0, @p1, @p2, @p3, @p4, @p5)


I have no idea however, why the DRIVERADDRESSESID is also being given as parameter in the insert statement. According to me this is not necessary at all.

Does anyone have an idea on how to solve this?


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.