Greetings,
I have encountered a bug in Torque, and unfortunately, I don't know
enough about the Torque codebase to be able to interpret the bug
in context. I have reduced the bug-producing setup down to the
simplest form. Following is how to generate it. I am using the
latest version of Torque -- version 3.0 b4 with postgresql.
Symptoms: The java source won't compile, and if I attempt to correct
the apparent problem (by escaping the quotes with \) the NumberKey
constructor is passed a non-numerical string which ends up throwing
an uncaught NumberFormatException because it is attempting to convert
the string into an integer.
I would greatly appreciate any pointers on how to overcome this
bug. Thank you very much,
Patryk Laurent
(1) SQL to create the database
------------------------------
drop sequence disjunctions_disjunction_id_seq;
drop table disjunctions ;
create table disjunctions (
disjunction_id serial primary key,
mode_id integer not null
) ;
(2) Generate the schema file from the database (here called "activ")
--------------------------------------------------------------------
[patryk@tanooki torque-3.0-b4]$ ant -f build-torque.xml jdbc
[patryk@tanooki torque-3.0-b4]$ mv schema/schema.xml schema/activ-schema.xml
(3) Generate the java source
----------------------------
[patryk@tanooki torque-3.0-b4]$ ant -f build-torque.xml
(4) Examine the erroneous line in the generate source; note the nested quotes.
------------------------------------------------------------------------------
(This will not compile.)
[patryk@tanooki torque-3.0-b4]$ cd src/java/org/apache/torque/
[patryk@tanooki torque]$ grep nextval BaseDisjunctions.java
private NumberKey disjunction_id= new
NumberKey("nextval('"disjunctions_disjunction_id_seq"'::text)");
(5) Attempt to correct by escaping quotes.
------------------------------------------
Buggy line: private NumberKey disjunction_id= new
NumberKey("nextval('"disjunctions_disjunction_id_seq"'::text)");
Corrected line: private NumberKey disjunction_id= new
NumberKey("nextval('\"disjunctions_disjunction_id_seq\"'::text)");
(6) Execute and examine the uncaught NumberFormatException.
-----------------------------------------------------------
Code:
Disjunctions tempDisjunction = new Disjunctions();
tempDisjunction.setModeId("12345");
tempDisjunction.save();
Result:
Exception in thread "main" java.lang.NumberFormatException:
xtval('"disjunctions_disjunction_id_
seq"'::text)
at java.lang.Integer.parseInt(Integer.java:426)
at java.lang.Integer.parseInt(Integer.java:476)
at java.math.BigDecimal.<init>(BigDecimal.java:210)
at org.apache.torque.om.NumberKey.<init>(NumberKey.java:84)
at org.apache.torque.BaseDisjunctions.<init>(BaseDisjunctions.java:43)
at org.apache.torque.Disjunctions.<init>(Disjunctions.java:16)
[end]
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>