I should reiterate that "create" works just fine - nicely sequenced unique ids as one would expect.
"Update" does not work because it seems that Castor (incorrectly) increments the id. I gave the sequence aliasing a go just to be thorough but it's not fixed the problem I'm afraid. Regards Max -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: 28 January 2003 23:23 To: [EMAIL PROTECTED] Subject: Re: [castor-dev] Apparent JDO bug with update and sequences Sorry, just add the alias for the sequence and use that in the key-generator phrase and it should work. <from the docs/> <key-generator name="SEQUENCE" alias="A"> <param name="sequence" value="a_seq"/> </key-generator> <key-generator name="SEQUENCE" alias ="RETURNING"> <param name="sequence" value="b_seq"/> <param name="returning" value="true"/> </key-generator> <class name="myapp.ProductGroup" identity="id" key-generator ="RETURNING"> <field name="id"> </field> </class> Terry O'Connor Sandbox Systems Direct (403) 444-2837 Fax (403) 444-2839 1-866-444-SAND [EMAIL PROTECTED] www.sandboxsystems.com terry.oconnor@sandboxs ystems.com To: [EMAIL PROTECTED] cc: 01/28/2003 02:49 PM Subject: Re: [castor-dev] Apparent JDO bug with update and sequences Please respond to castor-dev Just a guess but you have defined "key-generator name="SEQUENCE"" which is predefined by the JDO as your database generator. Try changing the name of the sequence generator OR delete your generator and just use the DB generator. Terry O'Connor Sandbox Systems Direct (403) 444-2837 Fax (403) 444-2839 1-866-444-SAND [EMAIL PROTECTED] www.sandboxsystems.com "Max Johnson" <max.johnson@deal To: [EMAIL PROTECTED] spark.com> cc: Subject: Re: [castor-dev] Apparent JDO bug with update and sequences 01/28/2003 02:07 PM Please respond to castor-dev Hi Robin Thanks for the fast response. Unfortunately, your suggestion doesn't resolve the problem. I changed the table definition to: CREATE TABLE users ( id INTEGER, -- Unique id user_name TEXT, -- User name password TEXT, -- Password CONSTRAINT pk_users PRIMARY KEY (id) ); i.e. Postgres no longer gets involved in assigning id's to new rows. The same reult I'm afraid: org.exolab.castor.jdo.PersistenceException: The identity of a data object of type com.dealspark.memorypack.data.jdo.UserProfileJDO, has been changed from 3 to 4 since it is loaded/create/update. To be honest I thought "id INTEGER DEFAULT nextval('users_id_seq')" would only generate an id when one wasn't supplied in the initial creation. Either way, it doesn't work! :-( It strikes me that a call to update should NEVER attempt any kind of sequence numbering so it's strange that Castor is doing this. Any more ideas? Max -----Original Message----- From: Robin Hoogeboom [mailto:[EMAIL PROTECTED]] Sent: 28 January 2003 20:06 To: [EMAIL PROTECTED] Subject: Re: [castor-dev] Apparent JDO bug with update and sequences Hi Max, All your settings seems to be ok, but (there it is) you don't have to use a sequence in the database. A sequence is embedded in Castor, and now the Castor sequence gives you a number and after that, the sequence from the database gives you one. That's why you've got an error like "First it's 14 and than you make it 15" Just create a table with the name sequence, and do not use a database sequence. Watch out for keyword in your database. Sometimes a keyword in your database cannot be used. Good luck. Robin Hoogeboom ----- Original Message ----- From: "Max Johnson" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, January 28, 2003 8:42 PM Subject: [castor-dev] Apparent JDO bug with update and sequences > I am using castor-0.9.4.2 JDO mapped to a PostgreSQL database. To best > explain I have broken the problem into three relevent parts: > > 1) A description of the PostgreSQL table > 2) A description of the corresponding Castor JDO mapping > 3) A description of the actual problem > > > 1) The PostgreSQL table > > The table takes a user name and password, and generates a unique id from a > sequence. It is configured as follows: > > CREATE SEQUENCE users_id_seq MINVALUE 1; > CREATE TABLE users ( > id INTEGER -- Unique id > DEFAULT nextval('users_id_seq'), > user_name TEXT, -- User name > password TEXT, -- Password > CONSTRAINT pk_users > PRIMARY KEY (id) > ); > > > 2) The Castor JDO mapping.xml > > The corresponding Castor JDO mapping.xml shown below: > > <!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN" > "http://castor.exolab.org/mapping.dtd"> > <mapping> > <key-generator name="SEQUENCE"> > <param name="sequence" value="{0}_{1}_seq"/> > <param name="trigger" value="false"/> > </key-generator> > > <!-- Mapping for users table --> > <class name="com.dealspark.memorypack.data.jdo.UserProfileJDO" > identity="id" > key-generator="SEQUENCE" cache-type="unlimited"> > <description>User Profiles</description> > <map-to table="users" xml="users" /> > <field name="id" type="integer" > > <sql name="id" type="integer"/> > <xml name="id" node="attribute"/> > </field> > <field name="username" type="string"> > <sql name="user_name" type="varchar"/> > <xml name="user_name" node="element" /> > </field> > <field name="password" type="string"> > <sql name="password" type="varchar"/> > <xml name="password" node="element" /> > </field> > </class> > </mapping> > > The mapped Java class is declared as follows: > > public class UserProfileJDO implements TimeStampable { > > ... fields and accessors as per the mapping.xml > } > > > 3) The actual problem - updates for long lived transactions don't work! > > Ok, so using the above config I can create an entry in the database by > passing a UserProfileJDO to the create method... > > public void create( Object object ) throws Exception { > > Database db = _jdo.getDatabase(); > db.begin(); > db.create(object); > db.commit(); > db.close(); > } > > This works! The object is written as a new row in the 'users' table. (Note: > 'id' is left null and is populated by PostgreSQL.) > > So next thing I want to do is change a field (e.g. 'password'). So I create > a new UserProfileJDO with the same id as the earlier object. I pass this > object to the update method... > > public void update( Object object ) throws Exception { > > Database db = _jdo.getDatabase(); > db.begin(); > db.update(object); > db.commit(); > db.close(); > } > > This time I get an exception: > > org.exolab.castor.jdo.TransactionAbortedException: Nested error: > org.exolab.castor.jdo.PersistenceException: The identity of a data object of > type com.dealspark.memorypack.data.jdo.UserProfileJDO, has been changed from > 14 to 15 since it is loaded/create/update. > at org.exolab.castor.persist.TransactionContext.prepare(Unknown > Source) > at org.exolab.castor.jdo.engine.DatabaseImpl.commit(Unknown Source) > > Which seems to indicate that update is trying to assign a new id to the > object! > > Is it a bug, a "can't be done", or am I just doing it wrong? Any help would > be very much appreciated. > > Regards > > Max > > ----------------------------------------------------------- > If you wish to unsubscribe from this mailing, send mail to > [EMAIL PROTECTED] with a subject of: > unsubscribe castor-dev ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev
