You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Mathieu Frenette <ma...@freeborders.com> on 2002/02/14 14:23:31 UTC

Does anyone got IDBroker to work with .save()?

Hello!

When I create a new OM object with a non-specified (null) PK and save it to
the DB, the IDBroker doesn't get invoked.

For example, the following:

	MyObj obj = new MyObj(null, "John", "Smith");
	obj.save();

Would result in the following row being inserted:

	null, "John", "Smith"

Even if my IDBroker and ID_TABLE are correctly configured.

I traced into the Peer code and understood why, but I can't see how to get
it to work without modifying Torque's source code.  Here are my findings:

The object's save() method calls the Peer's doInsert(), which in turn calls
buildCriteria().  buildCriteria() creates a criterion for *every* column of
the table, *including* the PK, even if this PK is null!

However, since my OM object doesn't have a PK (obviously it is null at this
point in time), a criterion for "PK=null" is added to Criteria.  Then,
finally, when Torque needs to determine whether or not to use the IDBroker,
it checks to see if the PK is specified in the Criteria, which is the case
(but it doesn't check to see whether the *value* of the criteria is null,
only if it is present).  So it decides not to use the IDBroker.

I simply cannot understand how the IDBroker can be used, other than by using
it manually.  The automatic behavior could never be called, at least not
when calling .save() or .doInsert() for a new OM object, which always have a
null PK.

I couldn't find any documentation regarding ID generation, so any help would
be greatly appreciated...

Best regards,
	Mathieu Frenette
	Software Architect
	Freeborders Canada inc.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Does anyone got IDBroker to work with .save()?

Posted by David Wynter <da...@btclick.com>.
Are you using

obj.setModified(false);
obj.setNew(true);

Before calling obj.save(); ?

Similarly use
obj.setModified(true);
obj.setNew(false);
when updating a OM object that already exists.



-----Original Message-----
From: Mathieu Frenette [mailto:mathieu.frenette@freeborders.com]
Sent: 14 February 2002 13:24
To: 'Turbine Users List'
Subject: Does anyone got IDBroker to work with .save()?


Hello!

When I create a new OM object with a non-specified (null) PK and save it to
the DB, the IDBroker doesn't get invoked.

For example, the following:

	MyObj obj = new MyObj(null, "John", "Smith");
	obj.save();

Would result in the following row being inserted:

	null, "John", "Smith"

Even if my IDBroker and ID_TABLE are correctly configured.

I traced into the Peer code and understood why, but I can't see how to get
it to work without modifying Torque's source code.  Here are my findings:

The object's save() method calls the Peer's doInsert(), which in turn calls
buildCriteria().  buildCriteria() creates a criterion for *every* column of
the table, *including* the PK, even if this PK is null!

However, since my OM object doesn't have a PK (obviously it is null at this
point in time), a criterion for "PK=null" is added to Criteria.  Then,
finally, when Torque needs to determine whether or not to use the IDBroker,
it checks to see if the PK is specified in the Criteria, which is the case
(but it doesn't check to see whether the *value* of the criteria is null,
only if it is present).  So it decides not to use the IDBroker.

I simply cannot understand how the IDBroker can be used, other than by using
it manually.  The automatic behavior could never be called, at least not
when calling .save() or .doInsert() for a new OM object, which always have a
null PK.

I couldn't find any documentation regarding ID generation, so any help would
be greatly appreciated...

Best regards,
	Mathieu Frenette
	Software Architect
	Freeborders Canada inc.


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>