You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Dan Diephouse <di...@compassarts.org> on 2001/04/21 20:48:45 UTC

Torque, Turbine and FK

I have a quicky question on foreign keys...  If I have a table defined
in my project-schema.xml with foreign keys in it I get multiple methods
in my table object file which are named the same.  That is I get one
method called getBusinessObject() which returns a NumberKey and another
getBusinessObject() which returns BusinessObject.  Java does not allow
this.... Am I doing something wrong when I generate me OM files?  Or do
I need to go through each of my files by hand and remove one method or
the other?  Or should I just change the torque template files?

Thanks,

Dan Diephouse


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Criteria --- OR?

Posted by John McNally <jm...@collab.net>.
The toString method is only printing part of the sql as the columns have
not yet been determined, It is just a diagnostic.  To print out the
actual sql set the relevant logger property in TR.props to DEBUG.  The
malformed sql is due to using TaskPeer.CUSER for the column.  You should
just give the column name, not fully qualified.  I know it is a bit
messy.  I have some ideas on cleaning this up, but it is going to wait
till after the release.

john mcnally

Jeremy C wrote:
> 
>              Criteria criteria = new Criteria();
>              criteria.add(TaskPeer.ASSIGNEDTO,
> user.getPrimaryKey().getValue());
>              Criteria.Criterion criterion =
> criteria.getCriterion(TaskPeer.ASSIGNEDTO);
>              criterion.or(
>                  criteria.getNewCriterion(
>                      criterion.getTable(),
>                      TaskPeer.CUSER,
>                      user.getPrimaryKey().getValue(),
>                      Criteria.EQUAL));
> 
>              criteria.addOrderByColumn(TaskPeer.PRIORITY);
>              criteria.addOrderByColumn(TaskPeer.STATUS);
> 
> produces: (criteria.toString())
> 
> Criteria:: task.ASSIGNEDTO<=>(task.ASSIGNEDTO=2 OR (task.task.CUSER=2)):
> Current SQL: SELECT FROM task, WHERE (task.ASSIGNEDTO=2 OR
> (task.task.CUSER=2)) ORDER BY task.PRIORITY, task.STATUS
> 
> The SQL statement is malformed.
> 
> It references task.task.CUSER, also it is not placing "*" (STAR) between
> SELECT and FROM (is it required by MySQL?)
> 
> Am I doing something wrong?
> 
> Jeremy - jeremy@cowgar.com
> 
> >At 05:13 PM 4/21/2001 -0700, you wrote:
> >>See documentation on Advanced Criteria and substitute .or() for .and()
> >>in the criterion chaining examples.
> >>
> >>john mcnally
> >>
> >>Jeremy C wrote:
> >> >
> >> > Is there a way to say something like:
> >> >
> >> > crit.add(Task.ASSIGNED_TO, currentUserId)
> >> > ---OR--
> >> > crit.add(Task.OWNER, currentUserId)
> >> >
> >> > (create's a SQL statement like:
> >> > SELECT * FROM TASK WHERE ASSIGNED_TO = 2 OR OWNER = 2
> >> >
> >> > Vector v = TaskPeer.doSelect(crit)
> >> >
> >> > ???
> >> >
> >> > Thanks!
> >> >
> >> > Jeremy - jeremy@cowgar.com
> >> >

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Criteria --- OR?

Posted by Jeremy C <je...@cowgar.com>.
             Criteria criteria = new Criteria();
             criteria.add(TaskPeer.ASSIGNEDTO, 
user.getPrimaryKey().getValue());
             Criteria.Criterion criterion = 
criteria.getCriterion(TaskPeer.ASSIGNEDTO);
             criterion.or(
                 criteria.getNewCriterion(
                     criterion.getTable(),
                     TaskPeer.CUSER,
                     user.getPrimaryKey().getValue(),
                     Criteria.EQUAL));

             criteria.addOrderByColumn(TaskPeer.PRIORITY);
             criteria.addOrderByColumn(TaskPeer.STATUS);

produces: (criteria.toString())


Criteria:: task.ASSIGNEDTO<=>(task.ASSIGNEDTO=2 OR (task.task.CUSER=2)): 
Current SQL: SELECT FROM task, WHERE (task.ASSIGNEDTO=2 OR 
(task.task.CUSER=2)) ORDER BY task.PRIORITY, task.STATUS

The SQL statement is malformed.

It references task.task.CUSER, also it is not placing "*" (STAR) between 
SELECT and FROM (is it required by MySQL?)

Am I doing something wrong?

Jeremy - jeremy@cowgar.com


>At 05:13 PM 4/21/2001 -0700, you wrote:
>>See documentation on Advanced Criteria and substitute .or() for .and()
>>in the criterion chaining examples.
>>
>>john mcnally
>>
>>Jeremy C wrote:
>> >
>> > Is there a way to say something like:
>> >
>> > crit.add(Task.ASSIGNED_TO, currentUserId)
>> > ---OR--
>> > crit.add(Task.OWNER, currentUserId)
>> >
>> > (create's a SQL statement like:
>> > SELECT * FROM TASK WHERE ASSIGNED_TO = 2 OR OWNER = 2
>> >
>> > Vector v = TaskPeer.doSelect(crit)
>> >
>> > ???
>> >
>> > Thanks!
>> >
>> > Jeremy - jeremy@cowgar.com
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
>> > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: turbine-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Criteria --- OR?

Posted by Jeremy C <je...@cowgar.com>.
I'm sorry for such a stupid question.

I printed the web pages and put them in my three ring binder. I was up and 
down the pages looking for help and I couldn't find it. Here to find, that 
the last page of the advcriteria.html is not there! The header says 4 of 5, 
then the next is 1 of 5 on Torque...

Sorry!

Jeremy - jeremy@cowgar.com

At 05:13 PM 4/21/2001 -0700, you wrote:
>See documentation on Advanced Criteria and substitute .or() for .and()
>in the criterion chaining examples.
>
>john mcnally
>
>Jeremy C wrote:
> >
> > Is there a way to say something like:
> >
> > crit.add(Task.ASSIGNED_TO, currentUserId)
> > ---OR--
> > crit.add(Task.OWNER, currentUserId)
> >
> > (create's a SQL statement like:
> > SELECT * FROM TASK WHERE ASSIGNED_TO = 2 OR OWNER = 2
> >
> > Vector v = TaskPeer.doSelect(crit)
> >
> > ???
> >
> > Thanks!
> >
> > Jeremy - jeremy@cowgar.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: turbine-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Criteria --- OR?

Posted by John McNally <jm...@collab.net>.
See documentation on Advanced Criteria and substitute .or() for .and()
in the criterion chaining examples.

john mcnally

Jeremy C wrote:
> 
> Is there a way to say something like:
> 
> crit.add(Task.ASSIGNED_TO, currentUserId)
> ---OR--
> crit.add(Task.OWNER, currentUserId)
> 
> (create's a SQL statement like:
> SELECT * FROM TASK WHERE ASSIGNED_TO = 2 OR OWNER = 2
> 
> Vector v = TaskPeer.doSelect(crit)
> 
> ???
> 
> Thanks!
> 
> Jeremy - jeremy@cowgar.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Criteria --- OR?

Posted by Jeremy C <je...@cowgar.com>.
Is there a way to say something like:

crit.add(Task.ASSIGNED_TO, currentUserId)
---OR--
crit.add(Task.OWNER, currentUserId)

(create's a SQL statement like:
SELECT * FROM TASK WHERE ASSIGNED_TO = 2 OR OWNER = 2

Vector v = TaskPeer.doSelect(crit)

???

Thanks!

Jeremy - jeremy@cowgar.com


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Torque, Turbine and FK

Posted by Daniel Rall <dl...@collab.net>.
Dan Diephouse <di...@compassarts.org> writes:

> I have a quicky question on foreign keys...  If I have a table defined
> in my project-schema.xml with foreign keys in it I get multiple methods
> in my table object file which are named the same.  That is I get one
> method called getBusinessObject() which returns a NumberKey and another
> getBusinessObject() which returns BusinessObject.  Java does not allow
> this.... Am I doing something wrong when I generate me OM files?  Or do
> I need to go through each of my files by hand and remove one method or
> the other?  Or should I just change the torque template files?

The version of the method that returns an ObjectKey sub class should
be called getBusinessObjectId().

Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Torque, Turbine and FK

Posted by John McNally <jm...@collab.net>.
This could happen if you name a column the same as a table which you are
referencing via a foreign key.

If I were to fix this in torque and follow the naming conventions that
solves other conflicts you would end up with methods 

NumberKey getBO()

and

BO getBORelatedByBO()

which is slightly confusing.  I would suggest not naming things like
this.  If you want to leave your column name as it is, you can use the
column javaName="BusObjId" to resolve the conflict in the java classes.

john mcnally 

Dan Diephouse wrote:
> 
> I have a quicky question on foreign keys...  If I have a table defined
> in my project-schema.xml with foreign keys in it I get multiple methods
> in my table object file which are named the same.  That is I get one
> method called getBusinessObject() which returns a NumberKey and another
> getBusinessObject() which returns BusinessObject.  Java does not allow
> this.... Am I doing something wrong when I generate me OM files?  Or do
> I need to go through each of my files by hand and remove one method or
> the other?  Or should I just change the torque template files?
> 
> Thanks,
> 
> Dan Diephouse
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org