-->
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.  [ 2 posts ] 
Author Message
 Post subject: can not insert entity with composite-id
PostPosted: Tue Mar 25, 2008 4:42 pm 
Newbie

Joined: Tue Mar 25, 2008 4:35 pm
Posts: 1
I have a problem when insert an entity with composite-id

mapping file
Code:
<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    namespace="WorkRequest.Data.Entity" assembly="WorkRequest.Data.Entity">

  <class name="PartOrder" table="tblWRPartsOrdering">

    <composite-id class="PartOrderPK" name="PartOrderPK">
      <key-property name="WorkRequestNumber"/>
      <key-property name="PartNumber"/>
    </composite-id>
    <property name="PartDescription" column="PartDesc" />     
    <property name="UnitCost" />   
    <property name="Quantity" column="Qty"/>
    <property name="DateReceived" />

    <many-to-one name="OrderedBy" class="WorkRequest.Data.Entity.User">
      <column name="OrderedBy"></column>
    </many-to-one>
    <many-to-one name="WorkRequest" class="WorkRequest.Data.Entity.WR">
      <column name="WorkRequestNumber"></column>
    </many-to-one>
  </class>
</hibernate-mapping>


code to save entity
Code:
PartOrder order = new PartOrder();

            PartOrderPK pk = new PartOrderPK();
            pk.PartNumber = "sss";
            pk.WorkRequestNumber = 62912;
            order.PartOrderPK = pk;

            order.DateReceived = DateTime.Now;

            //order.PartNumber = "sss";
            //order.WorkRequestNumber = 62912;

            session.Save(order);


when I debug. I see that nhibernate not procedure any insert query. I have show sql = true, but the console only show the query when I insert an entity with no composite id. no thing with this entity.

thanks in advanced


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 26, 2008 4:00 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You have to flush the session or commit the transaction if you use one. session.Save() just indicates that you want to persist a new object. Hibernate won't issue any sql unless the session is flushed.

_________________
--Wolfgang


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

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.