• 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
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
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: 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>
  • Date: Mon, 5 Nov 2007 16:21:32 -0800

WebObjects (specifically EOF) does not play nicely with identity columns. It is going to be very difficult to make it work. If you search the archives you can many threads on this topic. I think there were some potential solutions posted as well. Unless you are trying to co-exist with applications that write to these tables and rely on the identity column, you are much better off without them when using EOF.

Chuck


On Nov 5, 2007, at 4:14 PM, Wang, Iris wrote:

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:
40global-village.net


This email sent to email@hidden

--

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects






_______________________________________________
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


References: 
 >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>)

  • Prev by Date: Re: java.lang.AbstractMethodError at org.apache.axis.AxisEngine.refreshGlobalOptions(AxisEngine.java:502)
  • Next by Date: Array of Objects to Array of Global IDs ?
  • Previous by thread: Error associating with inserting a new record into the table in SQL Server 2005 database when its primary key's IDENTITY SPECIFICATION is YES
  • Next by thread: Array of Objects to Array of Global IDs ?
  • Index(es):
    • Date
    • Thread