• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Error associating with inserting a new record into the table in SQL Server 2005 database when its primary key's IDENTITY SPECIFICATION is YES
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Error associating with inserting a new record into the table in SQL Server 2005 database when its primary key's IDENTITY SPECIFICATION is YES


  • Subject: Error associating with inserting a new record into the table in SQL Server 2005 database when its primary key's IDENTITY SPECIFICATION is YES
  • From: "Wang, Iris" <email@hidden>
  • Date: Mon, 5 Nov 2007 16:14:21 -0800
  • Thread-topic: Error associating with inserting a new record into the table in SQL Server 2005 database when its primary key's IDENTITY SPECIFICATION is YES

Hello,

 

Can anyone give me some suggestions about dealing with WebObjects application running against SQL Server 2005 database when the table’s primary key is set to automatically generate? Any help will be greatly appreciated.

 

In order to identify the problem, I have let our DBA create a stand alone table without any relationships with other tables in the database, and I’ve created a simple application for testing.

 

The table is called test_contact_log. contact_log_id column is its primary key, and its type is int. For simplicity, I allow all columns are nullable except primary key column. 

 

When primary key’s IDENTITY SPECIFICATION set to NO, I can successfully retrieve and update old record and insert new record into table.

 

Using almost same set of WebObjects code, when primary key’s “Is Identity” is set to YES to turn on SQL server’s function of automatically generating primary key, I can still successfully retrieve and update existing record, but inserting new record gives me error “…The server failed to resume the transaction…”.  Statement .saveChanges()

 

In order to insert new record into database when IDENTITY SPECIFICATION is YES, I did following steps:

1. I commented off .setContactLogId statement in my WebObjects code not to manually give primary key value.

2. in EOModeler, I unchecked diamond icon and generated java class file for this entity not containing GET and SET method for contactLogId attribute (corresponding contact_log_id column in table).

3. In my Mac pc, I did put sqljdbc.jar (Date Modified Apr 23, 2007) into the directory Macintosh HD -> Library -> Java -> Extensions.

 

What more I need to do or what wrong I’ve done to make my application fail on inserting new record when the primary key is set to automatic generate?

 

The code is attached below:

 

public class Main extends WOComponent {

 

     protected TestContactLog selectedLog;

// TestContactLog is generated class in WebObjects corresponding to test_contact_log table in SQL

//Server 2005

 

public Main accessTestContactLog()

            //accessTestContactLog() is the method to be called when button on the screen is clicked.

{

       Main nextPage = (Main)pageWithName("Main");

       //Insert a new record into test_contact_log table

       EOFetchSpecification fs;

       EOEditingContext ecInsert = session().defaultEditingContext();

       fs = new EOFetchSpecification("TestContactLog", null, null);

       NSArray tempList = ecInsert.objectsWithFetchSpecification(fs);

      

       TestContactLog tcl = new TestContactLog();

       //  tcl.setContactLogId(new Integer(9));      

       tcl.setContactId(new Integer(721));

        //Record contact_id = 721 doesn’t exit yet in test_contact_log table .

       tcl.setLogonDate(new NSTimestamp());

       tcl.setLogoffDate(new NSTimestamp());

       tcl.setLastUpdDate(new NSTimestamp());

       tcl.setLastUpdUser("tester");

      

       ecInsert.insertObject(tcl);

       //  System.out.println("tcl.contactLogId() = " + tcl.contactLogId());  

       System.out.println("tcl.contactId() = " + tcl.contactId());

       System.out.println("tcl.logonDate() = " + tcl.logonDate());

       System.out.println("tcl.logoffDate() = " + tcl.logoffDate());

       System.out.println("tcl.lastUpdDate = " + tcl.lastUpdDate());  

       System.out.println("tcl.lastUpdUser = " + tcl.lastUpdUser());  

       System.out.println("before saveChanges()");                

       ecInsert.saveChanges();

       System.out.println("after saveChanges()");

      

       return nextPage;

    }

}

 

Thank you very much for any suggestion,

Iris

 

 

 

 

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Error associating with inserting a new record into the table in SQL Server 2005 database when its primary key's IDENTITY SPECIFICATION is YES
      • From: Chuck Hill <email@hidden>
  • Prev by Date: Re: java.lang.AbstractMethodError at org.apache.axis.AxisEngine.refreshGlobalOptions(AxisEngine.java:502)
  • Next by Date: Re: java.lang.AbstractMethodError at org.apache.axis.AxisEngine.refreshGlobalOptions(AxisEngine.java:502)
  • Previous by thread: Re: Question about EOs and their lifespan/uniqueness
  • Next by thread: Re: Error associating with inserting a new record into the table in SQL Server 2005 database when its primary key's IDENTITY SPECIFICATION is YES
  • Index(es):
    • Date
    • Thread