You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by "Gautam, Ajay" <ag...@ets.org> on 2004/02/20 16:19:24 UTC
ID_TABLE question
Hello
I was wondering if there is a document that explains the inner workings of
ID_TABLE's NEXT_ID management. Or maybe someone on this list could elobrate
on the same in view of the following issues:
I have set ID_TABLE to start at NEXT_ID from 1, and QUANTITY to 1;
#
# ID Broker Default Values
#
initialID = 101
torque.initialIDValue = 1
torque.initialIDStep = 1
As a part of setting up my (MySQL) database, I insert records in some of the
tables. (example) I insert 2 records in ITEM table, with ID values 1 and 2.
Here are my questions / issues:
1. How does ID_TABLE manage the NEXT_ID field ? Currently, ITEM table has a
NEXT_ID value of 28806, instead of "3" that I would expect. Similar is the
case with many other tables. How can I tell ID_TABLE to behave properly ?
2. How do I tell ID_TABLE to select max(ID) from the tables that it will
manage, and use MAX(ID) + 1 as the starting NEXT_ID value ? Inserting values
in tables does not work, as ID_TABLE has NEXT_ID value which already exists
in the table !.
I tried looking into the code, but got impatient, and left that avenue. I am
tried to search on google, but again got impatient ! :(
Any help / info would be highly appreciated.
Thanks in advance...
--
Ajay Gautam
**************************************************************************
This e-mail and any files transmitted with it may contain privileged or
confidential information. It is solely for use by the individual for whom
it is intended, even if addressed incorrectly. If you received this e-mail
in error, please notify the sender; do not disclose, copy, distribute, or
take any action in reliance on the contents of this information; and delete
it from your system. Any other use of this e-mail is prohibited. Thank you
for your compliance.
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: sequence related exception
Posted by Scott Eade <se...@backstagetech.com.au>.
Hassan Abolhassani wrote:
>What is wrong when an exception like below is thrown:
>
>org.apache.torque.TorqueException: ERROR: product_id_seq.currval is not
>yet defined in this session
> at org.apache.torque.util.BasePeer.throwTorqueException(BasePeer.java:236)
> at org.apache.torque.util.BasePeer.doInsert(BasePeer.java:780)
>
>And how it is possible to repair it?
>
You need to tell torque the correct PostgreSQL sequence name to use. See:
http://nagoya.apache.org/wiki/apachewiki.cgi?TorqueProjectPages/PostgreSQLFAQ
Scott
--
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: sequence related exception
Posted by Hassan Abolhassani <Ha...@xist-i.co.jp>.
Hi,
What is wrong when an exception like below is thrown:
org.apache.torque.TorqueException: ERROR: product_id_seq.currval is not
yet defined in this session
at org.apache.torque.util.BasePeer.throwTorqueException(BasePeer.java:236)
at org.apache.torque.util.BasePeer.doInsert(BasePeer.java:780)
And how it is possible to repair it?
Thanks
Hassan
___
xist-i Japan, Inc.
アボルハッサニ ハッサン Dr. Hassan Abolhassani [Technology network]
株式会社 レーザーフィッシュ・ジャパン
Hassan.Abolhassani@razorfish.co.jp
Tel:03-5436-9980 Fax:03-5436-9126
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: Transaction processing
Posted by Scott Eade <se...@backstagetech.com.au>.
Hassan Abolhassani wrote:
>I have a code like below to update several tables in one transaction:
>
>Connection con;
>try{
> con = Torque.getConnection();
> Agency agency = new Agency();
> ...
> agency.save(con);
> ...
>
> Product product = new Product();
> ...
> product.save(con);
>
>
>} catch (Exception e) {
> con.rollback();
>}
>finally {
> if (null != con) {
> try {
> Torque.closeConnection(con);
> } catch (Exception exp) {}
> }
>}
>
>
>When an exception occures inside the main block, the rollback() is not
>working. I mean some save operations updates database anyways.
>
>I am using postgress. Could anybody tell me how it might work?
>
You are simply sharing a connection, not using a transaction. You need
to do something like this:
Connection conn = null;
try
{
conn = Transaction.begin(Torque.getDefaultDB());
someObject.save(conn);
someOtherObject.save(conn);
Transaction.commit(conn);
}
catch (TorqueException ex)
{
try
{
Transaction.rollback(conn);
}
catch (TorqueException ex2)
{
log.error(ex2);
}
log.error(ex);
}
BTW: In the future can you please post as plain text rather than html.
Scott
--
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Transaction processing
Posted by Hassan Abolhassani <Ha...@xist-i.co.jp>.
Hi,
I have a code like below to update several tables in one transaction:
Connection con;
try{
con = Torque.getConnection();
Agency agency = new Agency();
...
agency.save(con);
...
Product product = new Product();
...
product.save(con);
} catch (Exception e) {
con.rollback();
}
finally {
if (null != con) {
try {
Torque.closeConnection(con);
} catch (Exception exp) {}
}
}
When an exception occures inside the main block, the rollback() is not
working. I mean some save operations updates database anyways.
I am using postgress. Could anybody tell me how it might work?
Regards,
Hassan
___
xist-i Japan, Inc.
アボルハッサニ ハッサン Dr. Hassan Abolhassani [Technology network]
株式会社 レーザーフィッシュ・ジャパン
Hassan.Abolhassani@razorfish.co.jp
Tel:03-5436-9980 Fax:03-5436-9126
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: Documentation and (slightly) strange update problem
Posted by ra...@mankin.org.uk.
Thanks, I'll give it a whirl.
As I said, I'm a newbie at Torque. I'm sure there are better ways of doing
things than I am using.
On 25-Feb-2004 Andras Balogh wrote:
> Hello,
>
> What about using the Criteria Object?
>
> Critetria crit=new Criteria();
> crit.add(ObjcontentPeer.folderID,folder.getObjid());
> crit.add(ObjcontentPeer.OBJ_ID,getObjid());
> List l=ObjcontentPeer.doSelect(crit);
>
>
> Best wishes,
> Andras.
>
> raph@mankin.org.uk wrote:
>
>>As requested, here is the code
>>
>>
>> /*
>> This does not work. Since we retrieved using two column values
>> it will save using those same two column values, but one of them
>> has changed, so the save will fail.
>> Objcontent link = new Objcontent(folder.getObjid(), getObjid());
>> List l = ObjcontentPeer.doSelect(link);
>> link = (Objcontent) l.get(0); // There can only be one instance
>> link.setFolderid(parent.getObjid());
>> link.save(); // This is the save() that does an INSERT instead of an
>>UPDATE
>> */
>>
>>
>>// This one does work.
>> List l = getObjcontentsRelatedByContentid();
>>LINK_UPDATE:
>> /*
>> This does work because we retrieve by PK and so the save will be by
>> PK
>> */
>> for (Iterator iter = l.iterator(); iter.hasNext(); ) {
>> Objcontent link = (Objcontent) (iter.next());
>> if (link.getFolderid() == folder.getObjid()) {
>> link.setFolderid(parent.getObjid());
>> link.save();
>> break LINK_UPDATE;
>> }
>> }
>>
>>
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
--
Never underexaggerate
Raphael Mankin
E-Mail: raph@panache.demon.co.uk
----------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: Documentation and (slightly) strange update problem
Posted by Andras Balogh <an...@reea.net>.
Hello,
What about using the Criteria Object?
Critetria crit=new Criteria();
crit.add(ObjcontentPeer.folderID,folder.getObjid());
crit.add(ObjcontentPeer.OBJ_ID,getObjid());
List l=ObjcontentPeer.doSelect(crit);
Best wishes,
Andras.
raph@mankin.org.uk wrote:
>As requested, here is the code
>
>
> /*
> This does not work. Since we retrieved using two column values
> it will save using those same two column values, but one of them
> has changed, so the save will fail.
> Objcontent link = new Objcontent(folder.getObjid(), getObjid());
> List l = ObjcontentPeer.doSelect(link);
> link = (Objcontent) l.get(0); // There can only be one instance
> link.setFolderid(parent.getObjid());
> link.save(); // This is the save() that does an INSERT instead of an
>UPDATE
> */
>
>
>// This one does work.
> List l = getObjcontentsRelatedByContentid();
>LINK_UPDATE:
> /*
> This does work because we retrieve by PK and so the save will be by PK
> */
> for (Iterator iter = l.iterator(); iter.hasNext(); ) {
> Objcontent link = (Objcontent) (iter.next());
> if (link.getFolderid() == folder.getObjid()) {
> link.setFolderid(parent.getObjid());
> link.save();
> break LINK_UPDATE;
> }
> }
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: Documentation and (slightly) strange update problem
Posted by ra...@mankin.org.uk.
As requested, here is the code
/*
This does not work. Since we retrieved using two column values
it will save using those same two column values, but one of them
has changed, so the save will fail.
Objcontent link = new Objcontent(folder.getObjid(), getObjid());
List l = ObjcontentPeer.doSelect(link);
link = (Objcontent) l.get(0); // There can only be one instance
link.setFolderid(parent.getObjid());
link.save(); // This is the save() that does an INSERT instead of an
UPDATE
*/
// This one does work.
List l = getObjcontentsRelatedByContentid();
LINK_UPDATE:
/*
This does work because we retrieve by PK and so the save will be by PK
*/
for (Iterator iter = l.iterator(); iter.hasNext(); ) {
Objcontent link = (Objcontent) (iter.next());
if (link.getFolderid() == folder.getObjid()) {
link.setFolderid(parent.getObjid());
link.save();
break LINK_UPDATE;
}
}
..and here is the relevant part of the schema
<database
name="ermsdb"
defaultJavaNamingMethod="java"
defaultIdMethod="native">
<table name="ERMSObject" description="Base Object Table">
<column
name="ObjID"
required="true"
primaryKey="true"
type="INTEGER"
autoIncrement="true"
description="Master object for all ERMS objects"
/>
<column
name="ObjType"
required="true"
type="CHAR"
size="1"
inheritance="single"
description="Discriminates between folders, parts, documents and
versions"
>
<inheritance key="D"
class="Document"
extends="uk.org.mankin.erms.Ermsobject"
/>
<inheritance key="V"
class="Version"
extends="uk.org.mankin.erms.Ermsobject"
/>
<inheritance key="U"
class="UserResource"
extends="uk.org.mankin.erms.Ermsobject"
/>
<inheritance key="C"
class="DocClass"
extends="uk.org.mankin.erms.Ermsobject"
/>
<inheritance key="F"
class="Folder"
extends="uk.org.mankin.erms.Ermsobject"
/>
<inheritance key="P"
class="Part"
extends="uk.org.mankin.erms.Ermsobject"
/>
<inheritance key="B"
class="Box"
extends="uk.org.mankin.erms.Ermsobject"
/>
<inheritance key="R"
class="Role"
extends="uk.org.mankin.erms.Ermsobject"
/>
</column>
<column
name="Name"
required="true"
type="VARCHAR"
size="255"
description="Object Title; free text"
/>
<column
name="Description"
type="VARCHAR"
size="255"
description="free text"
/>
<column
name="CreateDate"
type="TIMESTAMP"
/>
<column
name="OpenDate"
type="TIMESTAMP"
/>
<column
name="CloseDate"
type="TIMESTAMP"
/>
<column
name="PurgeHold"
type="BIT"
required="true"
default="0"
description="Do not purge even when a purge operation is
requested"
/>
<column
name="Status"
type="TINYINT"
required="true"
description="{New, Open, Closed, ClosePending, ReOpened, Inactive,
Archived}"
/>
<column
name="Creator"
type="INTEGER"
required="true"
description="A user ID; a FK"
/>
<column
name="Path"
type="LONGVARCHAR"
size="2048"
required="true"
description="The path name of where the object is in the
server's file store; it has nothing to do
with the logical name by which it referred
to in the EDRMS system."
/>
<column
name="Level"
type="INTEGER"
required="true"
/>
<foreign-key foreignTable="User">
<reference local="Creator" foreign="UserID"/>
</foreign-key>
<foreign-key foreignTable="SecurityLevel">
<reference local="Level" foreign="Level"/>
</foreign-key>
<!-- fields specific to Document -->
<column
name="DocTypeID"
type="INTEGER"
required="true"
/>
<column
name="Language"
type="VARCHAR"
size="255"
/>
<column
name="LockUser"
type="INTEGER"
description="The user who has checked out this doc"
/>
<column
name="LockTime"
type="TIMESTAMP"
description="When the document was checked out"
/>
<column
name="VitalRecord"
type="BIT"
required="true"
default="0"
description="A vital record is one that must never be
deleted, even during a purge"
/>
<foreign-key foreignTable="DocumentType" name="DocumentType">
<reference local="DocTypeID" foreign="DocTypeID"/>
</foreign-key>
<foreign-key foreignTable="User">
<reference local="LockUser" foreign="UserID"/>
</foreign-key>
<!-- Fields specific to document versions -->
<column
name="Version"
type="INTEGER"
required="true"
default="0"
/>
<column
name="DocFormatID"
type="INTEGER"
/>
<column
name="Checksum"
type="BIGINT"
/>
<column
name="ParentID"
type="INTEGER"
description="The document to which this version belongs"
/>
<foreign-key foreignTable="ERMSObject">
<reference local="ParentID" foreign="ObjID"/>
</foreign-key>
<foreign-key foreignTable="DocumentFormat">
<reference local="DocFormatID" foreign="DocFormatID"/>
</foreign-key>
</table>
<table name="ObjContent"
description="m:n join table specifying the content of each folder and
part">
<column
name="ContentPK"
required="true"
primaryKey="true"
type="INTEGER"
autoIncrement="true"
/>
<column
name="FolderID"
type="INTEGER"
required="true"
description="The ObjID of the containing folder"
/>
<column
name="ContentID"
type="INTEGER"
required="true"
description="The ObjID of the content object"
/>
<foreign-key foreignTable="ERMSObject">
<reference local="FolderID" foreign="ObjID"/>
</foreign-key>
<foreign-key foreignTable="ERMSObject">
<reference local="ContentID" foreign="ObjID"/>
</foreign-key>
<unique>
<unique-column name="FolderID"/>
<unique-column name="ContentID"/>
</unique>
</table>
</database>
On 25-Feb-2004 Scott Eade wrote:
> raph@mankin.org.uk wrote:
>
>>As a newcomer to Torque, I would add that the lack of comprehensive
>>documentation has been my biggest difficulty. Is there a documentation
>>project
>>in hand? I think that such a project should even take precedece over fixing
>>bugs; if one at least has the wrinkles documented one can work around them,
>>and
>>AFAICT most are not major.
>>
> Everyone is welcome to contribute documentation. Send it to this list,
> the torque-dev list or add it to the wiki.
>
>>
>>To move on ... I encountered some unintuitive behaviour when doing an update.
>>
>>
>>I have a m:n join table. It looks something like
>>
>> create table link (
>> PK integer auto_increment, -- synthetic primary key
>> parent integer references mastertable,
>> child integer references mastertable
>> )
>>
>>Now, I wanted to move a child from one parent to a different parent i.e. just
>>update the 'parent' field in the link. I therefore selected on the
>>(parent,child) pair, amended the parent value and called save(). This is
>>where
>>things went wrong.
>>
>>Torque tried to save using the same criteria that it had used to select, but
>>I
>>had changed one of the values. It therefore did an INSERT instead of an
>>UPDATE
>>when what I wanted was that it should do an UPDATE using the primary key.
>>
>>The actual behaviour is clearly the intended behaviour. What I am questioning
>>is whether this is the correct behaviour. As we know from recent postings,
>>every table must have a primary key otherwise save() does not save. Given
>>that
>>there always is a primary key, should all UPDATEs *always* use that key and
>>not
>>the selection criteria?
>>
>>I worked around my problem, but good documentation would have made life much
>>easier.
>>
> Please post the relevant schema and code.
>
> Scott
>
> --
> Scott Eade
> Backstage Technologies Pty. Ltd.
> http://www.backstagetech.com.au
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
--
Never underexaggerate
Raphael Mankin
E-Mail: raph@panache.demon.co.uk
----------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: Documentation and (slightly) strange update problem
Posted by Scott Eade <se...@backstagetech.com.au>.
raph@mankin.org.uk wrote:
>As a newcomer to Torque, I would add that the lack of comprehensive
>documentation has been my biggest difficulty. Is there a documentation project
>in hand? I think that such a project should even take precedece over fixing
>bugs; if one at least has the wrinkles documented one can work around them, and
>AFAICT most are not major.
>
Everyone is welcome to contribute documentation. Send it to this list,
the torque-dev list or add it to the wiki.
>
>To move on ... I encountered some unintuitive behaviour when doing an update.
>
>
>I have a m:n join table. It looks something like
>
> create table link (
> PK integer auto_increment, -- synthetic primary key
> parent integer references mastertable,
> child integer references mastertable
> )
>
>Now, I wanted to move a child from one parent to a different parent i.e. just
>update the 'parent' field in the link. I therefore selected on the
>(parent,child) pair, amended the parent value and called save(). This is where
>things went wrong.
>
>Torque tried to save using the same criteria that it had used to select, but I
>had changed one of the values. It therefore did an INSERT instead of an UPDATE
>when what I wanted was that it should do an UPDATE using the primary key.
>
>The actual behaviour is clearly the intended behaviour. What I am questioning
>is whether this is the correct behaviour. As we know from recent postings,
>every table must have a primary key otherwise save() does not save. Given that
>there always is a primary key, should all UPDATEs *always* use that key and not
>the selection criteria?
>
>I worked around my problem, but good documentation would have made life much
>easier.
>
Please post the relevant schema and code.
Scott
--
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Documentation and (slightly) strange update problem
Posted by ra...@mankin.org.uk.
On 25-Feb-2004 Scott Eade wrote:
> Gautam, Ajay wrote:
>
>>I was wondering if there is a document that explains the inner workings of
>>ID_TABLE's NEXT_ID management. Or maybe someone on this list could elobrate
>>on the same in view of the following issues:
>>
> No document exists at this time.
>
As a newcomer to Torque, I would add that the lack of comprehensive
documentation has been my biggest difficulty. Is there a documentation project
in hand? I think that such a project should even take precedece over fixing
bugs; if one at least has the wrinkles documented one can work around them, and
AFAICT most are not major.
To move on ... I encountered some unintuitive behaviour when doing an update.
I have a m:n join table. It looks something like
create table link (
PK integer auto_increment, -- synthetic primary key
parent integer references mastertable,
child integer references mastertable
)
Now, I wanted to move a child from one parent to a different parent i.e. just
update the 'parent' field in the link. I therefore selected on the
(parent,child) pair, amended the parent value and called save(). This is where
things went wrong.
Torque tried to save using the same criteria that it had used to select, but I
had changed one of the values. It therefore did an INSERT instead of an UPDATE
when what I wanted was that it should do an UPDATE using the primary key.
The actual behaviour is clearly the intended behaviour. What I am questioning
is whether this is the correct behaviour. As we know from recent postings,
every table must have a primary key otherwise save() does not save. Given that
there always is a primary key, should all UPDATEs *always* use that key and not
the selection criteria?
I worked around my problem, but good documentation would have made life much
easier.
--
Never underexaggerate
Raphael Mankin
E-Mail: raph@panache.demon.co.uk
----------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: ID_TABLE question
Posted by Scott Eade <se...@backstagetech.com.au>.
Gautam, Ajay wrote:
>I was wondering if there is a document that explains the inner workings of
>ID_TABLE's NEXT_ID management. Or maybe someone on this list could elobrate
>on the same in view of the following issues:
>
No document exists at this time.
>I have set ID_TABLE to start at NEXT_ID from 1, and QUANTITY to 1;
>#
># ID Broker Default Values
>#
>initialID = 101
>torque.initialIDValue = 1
>torque.initialIDStep = 1
>
>As a part of setting up my (MySQL) database, I insert records in some of the
>tables. (example) I insert 2 records in ITEM table, with ID values 1 and 2.
>
>Here are my questions / issues:
>
>1. How does ID_TABLE manage the NEXT_ID field ? Currently, ITEM table has a
>NEXT_ID value of 28806, instead of "3" that I would expect. Similar is the
>case with many other tables. How can I tell ID_TABLE to behave properly ?
>
If you have torque create your tables it should use the torque.initialID
value when populating the table.
>2. How do I tell ID_TABLE to select max(ID) from the tables that it will
>manage, and use MAX(ID) + 1 as the starting NEXT_ID value ? Inserting values
>in tables does not work, as ID_TABLE has NEXT_ID value which already exists
>in the table !.
>
You can't directly tell torque to do this - you would need to update the
id table manually and ensure that torque is not prefetching id values.
From what you are describing you would be better off using
idMethod="native" and have MySQL manage the ids for you.
>I tried looking into the code, but got impatient, and left that avenue. I am
>tried to search on google, but again got impatient ! :(
>
That's very funny - I got quite impatient composing a response to you.
Scott
--
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org