You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by "Joseph P. Berglund" <jo...@yahoo.com> on 2010/12/17 20:57:59 UTC

non meaningful pk philosophy, and composite pk question

I am new to cayenne, and am enjoying it immensely! A few questions- 

A1) I understand that the use of automatically generated, non-meaningful primary keys is one of the philosophies supported by cayenne.

In this instance, what is the best practice method of referring to a row in a web based application when I do not have direct access to the primary key? 

I am assuming that I should create a UNIQUE attribute, like "name", that I can use to refer to that row, but I want to make sure that is the right track.

A2) If that is the case, are there any plans to implement easy access to the object through the data context / data object without an expression (and without me writing it in my generic wrapper object)? I.E. it would be nice if unique, non-pk rows could be access from the object itself... (I.e. when I need to grab a user name, performing User user = User.forName("joe") would rock my socks)

B) Much of the data I am dealing with I have defined with composite primary keys. With web applications, this involves me passing each key individually in an HTTP request. Is there any easy way I can pass a record identity for a composite primary key.? I have looked at the ObjectID, but from what I have seen, serializing/deserializing this requires more overhead than I am comfortable with as I dont need a specific reference to the ObjectID class, but to the row the class is identifying.

Thanks,
joey b.





      

Re: non meaningful pk philosophy, and composite pk question

Posted by "Joseph P. Berglund" <jo...@yahoo.com>.
Andrus, Steve,

Thank you, this is exactly the information I was looking for. 

Regards,
joey b.
--- On Fri, 12/17/10, Steve Springett <st...@springett.us> wrote:

> From: Steve Springett <st...@springett.us>
> Subject: Re: non meaningful pk philosophy, and composite pk question
> To: user@cayenne.apache.org
> Date: Friday, December 17, 2010, 4:45 PM
> Joey,
> 
> Additionally, I have typically employed the use of the UUID
> object to add
> support for secondary keys that are guaranteed to be
> unique. This approach
> seems to work well for web apps where I need a unique key
> for some record.
> 
> --Steve
> 
> 
> 
> On Fri, Dec 17, 2010 at 1:23 PM, Andrus Adamchik <an...@objectstyle.org>wrote:
> 
> > Hi Joey,
> >
> >
> > On Dec 17, 2010, at 9:57 PM, Joseph P. Berglund
> wrote:
> > > I am new to cayenne, and am enjoying it
> immensely! A few questions-
> > >
> > > A1) I understand that the use of automatically
> generated, non-meaningful
> > primary keys is one of the philosophies supported by
> cayenne.
> >
> > Yes.
> >
> > > In this instance, what is the best practice
> method of referring to a row
> > in a web based application when I do not have direct
> access to the primary
> > key?
> > >
> > > I am assuming that I should create a UNIQUE
> attribute, like "name", that
> > I can use to refer to that row, but I want to make
> sure that is the right
> > track.
> > >
> > > A2) If that is the case, are there any plans to
> implement easy access to
> > the object through the data context / data object
> without an expression (and
> > without me writing it in my generic wrapper object)?
> I.E. it would be nice
> > if unique, non-pk rows could be access from the object
> itself... (I.e. when
> > I need to grab a user name, performing User user =
> User.forName("joe") would
> > rock my socks)
> >
> > In general there isn't a natural second unique column
> in a table (the
> > opposite would be a special case IMO). So Cayenne
> doesn't try to address
> > this directly, leaving it up to the users to write
> such a "secondary PK"
> > lookup method if they adopt such pattern in their
> design.
> >
> > > B) Much of the data I am dealing with I have
> defined with composite
> > primary keys. With web applications, this involves me
> passing each key
> > individually in an HTTP request. Is there any easy way
> I can pass a record
> > identity for a composite primary key.? I have looked
> at the ObjectID, but
> > from what I have seen, serializing/deserializing this
> requires more overhead
> > than I am comfortable with as I dont need a specific
> reference to the
> > ObjectID class, but to the row the class is
> identifying.
> >
> > IIRC there were a few third-party implementations of
> this functionality,
> > usually attached to some frontend framework. Not so
> long ago I implemented
> > yet another one, available in a "sandbox" area of the
> Cayenne code repo:
> >
> > http://svn.apache.org/repos/asf/cayenne/sandbox/cayenne-mixin/trunk/
> >
> > more specifically:
> >
> >
> > http://svn.apache.org/repos/asf/cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/uuid/UuidCoder.java
> >
> > http://svn.apache.org/repos/asf/cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/ref/ReferenceableHandler.java
> >
> > The whole "cayenne-mixin" module idea is about
> building commonly-used
> > extensions of Cayenne, but the idea of a
> "referenceable" object is generic
> > enough, so it has a chance to be moved to the
> framework core in the future.
> > In the meantime you can copy this code and adapt for
> your app needs as you
> > wish.
> >
> > Andrus
> >
> >
> >
> 


      

Re: non meaningful pk philosophy, and composite pk question

Posted by Steve Springett <st...@springett.us>.
Joey,

Additionally, I have typically employed the use of the UUID object to add
support for secondary keys that are guaranteed to be unique. This approach
seems to work well for web apps where I need a unique key for some record.

--Steve



On Fri, Dec 17, 2010 at 1:23 PM, Andrus Adamchik <an...@objectstyle.org>wrote:

> Hi Joey,
>
>
> On Dec 17, 2010, at 9:57 PM, Joseph P. Berglund wrote:
> > I am new to cayenne, and am enjoying it immensely! A few questions-
> >
> > A1) I understand that the use of automatically generated, non-meaningful
> primary keys is one of the philosophies supported by cayenne.
>
> Yes.
>
> > In this instance, what is the best practice method of referring to a row
> in a web based application when I do not have direct access to the primary
> key?
> >
> > I am assuming that I should create a UNIQUE attribute, like "name", that
> I can use to refer to that row, but I want to make sure that is the right
> track.
> >
> > A2) If that is the case, are there any plans to implement easy access to
> the object through the data context / data object without an expression (and
> without me writing it in my generic wrapper object)? I.E. it would be nice
> if unique, non-pk rows could be access from the object itself... (I.e. when
> I need to grab a user name, performing User user = User.forName("joe") would
> rock my socks)
>
> In general there isn't a natural second unique column in a table (the
> opposite would be a special case IMO). So Cayenne doesn't try to address
> this directly, leaving it up to the users to write such a "secondary PK"
> lookup method if they adopt such pattern in their design.
>
> > B) Much of the data I am dealing with I have defined with composite
> primary keys. With web applications, this involves me passing each key
> individually in an HTTP request. Is there any easy way I can pass a record
> identity for a composite primary key.? I have looked at the ObjectID, but
> from what I have seen, serializing/deserializing this requires more overhead
> than I am comfortable with as I dont need a specific reference to the
> ObjectID class, but to the row the class is identifying.
>
> IIRC there were a few third-party implementations of this functionality,
> usually attached to some frontend framework. Not so long ago I implemented
> yet another one, available in a "sandbox" area of the Cayenne code repo:
>
> http://svn.apache.org/repos/asf/cayenne/sandbox/cayenne-mixin/trunk/
>
> more specifically:
>
>
> http://svn.apache.org/repos/asf/cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/uuid/UuidCoder.java
>
> http://svn.apache.org/repos/asf/cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/ref/ReferenceableHandler.java
>
> The whole "cayenne-mixin" module idea is about building commonly-used
> extensions of Cayenne, but the idea of a "referenceable" object is generic
> enough, so it has a chance to be moved to the framework core in the future.
> In the meantime you can copy this code and adapt for your app needs as you
> wish.
>
> Andrus
>
>
>

Re: non meaningful pk philosophy, and composite pk question

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Joey,


On Dec 17, 2010, at 9:57 PM, Joseph P. Berglund wrote:
> I am new to cayenne, and am enjoying it immensely! A few questions- 
> 
> A1) I understand that the use of automatically generated, non-meaningful primary keys is one of the philosophies supported by cayenne.

Yes.

> In this instance, what is the best practice method of referring to a row in a web based application when I do not have direct access to the primary key? 
> 
> I am assuming that I should create a UNIQUE attribute, like "name", that I can use to refer to that row, but I want to make sure that is the right track.
> 
> A2) If that is the case, are there any plans to implement easy access to the object through the data context / data object without an expression (and without me writing it in my generic wrapper object)? I.E. it would be nice if unique, non-pk rows could be access from the object itself... (I.e. when I need to grab a user name, performing User user = User.forName("joe") would rock my socks)

In general there isn't a natural second unique column in a table (the opposite would be a special case IMO). So Cayenne doesn't try to address this directly, leaving it up to the users to write such a "secondary PK" lookup method if they adopt such pattern in their design.

> B) Much of the data I am dealing with I have defined with composite primary keys. With web applications, this involves me passing each key individually in an HTTP request. Is there any easy way I can pass a record identity for a composite primary key.? I have looked at the ObjectID, but from what I have seen, serializing/deserializing this requires more overhead than I am comfortable with as I dont need a specific reference to the ObjectID class, but to the row the class is identifying.

IIRC there were a few third-party implementations of this functionality, usually attached to some frontend framework. Not so long ago I implemented yet another one, available in a "sandbox" area of the Cayenne code repo:

http://svn.apache.org/repos/asf/cayenne/sandbox/cayenne-mixin/trunk/

more specifically:

http://svn.apache.org/repos/asf/cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/uuid/UuidCoder.java
http://svn.apache.org/repos/asf/cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/ref/ReferenceableHandler.java

The whole "cayenne-mixin" module idea is about building commonly-used extensions of Cayenne, but the idea of a "referenceable" object is generic enough, so it has a chance to be moved to the framework core in the future. In the meantime you can copy this code and adapt for your app needs as you wish.

Andrus