You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by "Thomas Fischer (JIRA)" <ji...@apache.org> on 2007/10/14 13:27:50 UTC

[jira] Closed: (TORQUE-69) Record.save() may not work if there is no primary key but no error is thrown.

     [ https://issues.apache.org/jira/browse/TORQUE-69?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas Fischer closed TORQUE-69.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 3.3-RC3

An exception is now thrown an an attempt to update an object without primary key. The previous behavior was to fail silently.

> Record.save() may not work if there is no primary key but no error is thrown.
> -----------------------------------------------------------------------------
>
>                 Key: TORQUE-69
>                 URL: https://issues.apache.org/jira/browse/TORQUE-69
>             Project: Torque
>          Issue Type: Bug
>          Components: Runtime
>    Affects Versions: 3.3
>         Environment: WinXP / Java 1.5 / Tomcat 5.5 / MS SQL 
>            Reporter: CG Monroe
>            Priority: Minor
>             Fix For: 3.3-RC3
>
>
> Here's the situation.
> You have a table with no primary key. E.g. A table named Poor_Design with columns: FK1, FK2, Value1, Value2.
> You then retrieve a record object from that table, modify it, and then save it, e.g.
>   Criteria c = new Criteria();
>   c.add(PoorDesignPeer.FK1, fk1);
>   c.add(PoorDesignPeer.FK2, fk2);
>   List result = PoorDesignPeer.doSelect(c);
>   PoorDesign modifiedRec = (PoorDesign) results.get(0);
>   modifiedRec.setValue1(newValue);
>   modifiedRec.save();
> The save()  ( UPDATE ) to the DB will not suceed, but no error will be thrown indicating it failed.
> This also occur if PoorDesignPeer.doUpdate(modifiedRec) is used.
> This condition should probably throw an error in all cases, since there is no reliable way to locate the original record in the DB.
> In trying to trace it out, I suspect that there is probably some logic bug in the underlying BasePeer object.  This is probably related to the buildcriteria(object) not being able to identify modified fields from unmodified and therefore
> creating a criteria for a record that can't be retrieved again at lower levels.  But the logic for this is complicated.
> However, an easy way to fix this might be to just update the generated peer's doUpdate( object ) method to check for primary keys or not, and throw an exception here all the time.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


RE: [jira] Closed: (TORQUE-69) Record.save() may not work if there is no primary key but no error is thrown.

Posted by Greg Monroe <Gr...@DukeCE.com>.
Thomas Vandahl said on Wednesday, October 17, 2007 1:55 PM
> I'm not entirely sure if that is indeed the solution for the 
> problem (even if it has been suggested in the issue). 
> Sometimes one has to cope with existing database designs. In 
> this case, Torque would simply refuse to work - which is 
> least annoying.

IMHO, it's a bit more than annoying.  Especially, since this 
behaviour is not well documented.  It can take a great deal of
time to debug what is happening (especially since Torque 
doesn't log updates/deletes). 

In my particular case, I was creating a Torque based Data Access 
Object implimentation for jForum.  This has a LOT of poor DB 
design (mostly inherited from PhPBB which it was it's conversion 
basis..).  Plus, there was not a lot of testing that could be done 
until the full suite of 20 odd DAO interfaces were implimented. 
So by the time I knew there was a problem, I had to go back and 
manually identify all the places that didn't the work and didn't 
let me know they failed.  NOT FUN.

IMHO, any good object layer (O/R mapper, SoA, TCP, whatever) should 
include a "contract" proviso that if it can't do what you asked it
to, it should tell you and not just swallow exceptions/errors.
 
> I suspect that any O/R mapper will have problems with tables 
> without primary keys because there is no fixed object/record-relation.
> Nevertheless those table designs exist. How do others handle 
> this case?

OK, off the soap box now... FWIW, I dealt with this problem in three
main ways.  First, a lot of the tables did not have primary keys 
defined, but had "defacto" primary keys.  Generally in the form of
two or three fields that made the record unique. For these, I just
modified the XML schema to use these.  Torque was happy and it made
the SQL structure a little more robust.

In some cases, there was no definitive key fields.  For these, I 
could still use the Torque select and insert methods.  But for the
delete and update needs, I created manual SQL statements using 
Torque's field constants and called BasePeer.executeStatement 
with this.

It's been a while, but I also had a vague memory of using the
doUpdate(criteria, criteria) to fix some stuff as well.
DukeCE Privacy Statement:
Please be advised that this e-mail and any files transmitted with
it are confidential communication or may otherwise be privileged or
confidential and are intended solely for the individual or entity
to whom they are addressed. If you are not the intended recipient
you may not rely on the contents of this email or any attachments,
and we ask that you please not read, copy or retransmit this
communication, but reply to the sender and destroy the email, its
contents, and all copies thereof immediately. Any unauthorized
dissemination, distribution or copying of this communication is
strictly prohibited.

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Re: [jira] Closed: (TORQUE-69) Record.save() may not work if there is no primary key but no error is thrown.

Posted by Thomas Fischer <fi...@seitenbau.net>.
Other OR mappers remember the original values they have read from the db.
So they can
a) still select the original data row if no pk is available, or cope with
changed pk's (shudder, but every year somebody asks to do this on the user
list)
b) update only the changed fields (not sure if this is desirable, may kill
caching of prepared statements)
c) make the data available to the user

Maybe at some time in the future we should consider to keep the original
data.. But it also has problems:
- it increases the amount of memory an object needs
- it is more complicated

    Thomas


Thomas Vandahl <tv...@apache.org> schrieb am 17.10.2007 19:55:10:

> Thomas Fischer (JIRA) wrote:
> >      [
https://issues.apache.org/jira/browse/TORQUE-69?page=com.atlassian.
> jira.plugin.system.issuetabpanels:all-tabpanel ]
> >
> > Thomas Fischer closed TORQUE-69.
> > --------------------------------
> >
> >        Resolution: Fixed
> >     Fix Version/s: 3.3-RC3
> >
> > An exception is now thrown an an attempt to update an object without
primary
> key. The previous behavior was to fail silently.
>
> I'm not entirely sure if that is indeed the solution for the problem
> (even if it has been suggested in the issue). Sometimes one has to cope
> with existing database designs. In this case, Torque would simply refuse
> to work - which is least annoying.
>
> I suspect that any O/R mapper will have problems with tables without
> primary keys because there is no fixed object/record-relation.
> Nevertheless those table designs exist. How do others handle this case?
>
> Bye, Thomas.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-dev-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Re: [jira] Closed: (TORQUE-69) Record.save() may not work if there is no primary key but no error is thrown.

Posted by Thomas Vandahl <tv...@apache.org>.
Thomas Fischer (JIRA) wrote:
>      [ https://issues.apache.org/jira/browse/TORQUE-69?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
> 
> Thomas Fischer closed TORQUE-69.
> --------------------------------
> 
>        Resolution: Fixed
>     Fix Version/s: 3.3-RC3
> 
> An exception is now thrown an an attempt to update an object without primary key. The previous behavior was to fail silently.

I'm not entirely sure if that is indeed the solution for the problem
(even if it has been suggested in the issue). Sometimes one has to cope
with existing database designs. In this case, Torque would simply refuse
to work - which is least annoying.

I suspect that any O/R mapper will have problems with tables without
primary keys because there is no fixed object/record-relation.
Nevertheless those table designs exist. How do others handle this case?

Bye, Thomas.


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org