-->
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: Session.save / not working / empty insert
PostPosted: Fri Feb 10, 2006 4:00 pm 
Newbie

Joined: Sun May 09, 2004 2:45 pm
Posts: 14
Hello all. I am trying to use the Session.save(Object o) / Session.saveOrUpdate(Object o) function. I am passing all the parameters correctly, and getting no exceptions. However, there is is no record in the DB pertaining to the insert. Has anyone else come across this?

I'm including my SQL, hbm.xml, and Java code, just in case I've missed something.


SQL:
Code:
CREATE TABLE dbo.SP_Events
(
    EventId     numeric(12,0) NOT NULL,
    CloseDate   date          NOT NULL,
    TrustNumber numeric(12,0) NOT NULL,
    EventTypeId numeric(12,0) NULL,
    StatusId    numeric(12,0) NULL,
    Notes       varchar(256)  NULL,
    CONSTRAINT SP_Events_8285790091
    PRIMARY KEY CLUSTERED (EventId,CloseDate,TrustNumber)
)
LOCK ALLPAGES
go
IF OBJECT_ID('dbo.SP_Events') IS NOT NULL
    PRINT '<<< CREATED TABLE dbo.SP_Events >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE dbo.SP_Events >>>'
go




Mapping (hbm.xml):
Code:
<hibernate-mapping package="com.lehman.tims.persist">

    <class name="SpEvents" table="SP_Events">
        <composite-id name="id" class="SpEventsKey">
            <key-property name="closedate" column="CloseDate" type="java.lang.String"/>
            <key-property name="eventid" column="EventId" type="java.lang.Long"/>
            <key-property name="trustnumber" column="TrustNumber" type="java.lang.Long"/>
        </composite-id>

        <property name="eventtypeid" column="EventTypeId" type="java.lang.Long" />
        <property name="statusid" column="StatusId" type="java.lang.Long" />
        <property name="notes" column="Notes" type="java.lang.String" />
    </class>
   
</hibernate-mapping>




Java:
Code:
public static void main( String args[] ) {
   
   SpEventsKey eventsKey = new SpEventsKey();
   eventsKey.setClosedate("01/01/2006");
   eventsKey.setEventid( new Long("1") );
   eventsKey.setTrustnumber( new Long("14") );
   
   SpEvents events = new SpEvents();
   events.setId( eventsKey );
   events.setNotes( "Some notes" );
   
   session.save( events );
   session.flush();
   session.close();
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 5:36 pm 
Newbie

Joined: Sun May 09, 2004 2:45 pm
Posts: 14
Ooops. My bad. I should be doing this:


Code:
Transaction transaction = session.beginTransaction();
session.save( events );
transaction.commit();


/tim


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.