On 23/12/2007, at 6:07 AM, Terrence A. Pietrondi wrote:
(1) I added these notes to make mention of how to
handle key generation when this action is not handled
by the database, and without changes to the database.
So in my case, we wanted to increment the max for each
additional entry to the table (pretty basic). So in
order to tell the new entry to the table its id, I
needed to set its ObjectId with one that I came up
with.
All seemed to work well. In a threaded
environment, I think this would work since the select
and addition are all part of the same transaction on
the database. I added this because I didn't see how to
do this in any of the available documentation.
The simplest way to have Cayenne handle PK generation is to follow the
instructions here:
http://cayenne.apache.org/doc/generate-primary-key-support.html
That will implement a solution which is thread safe and portable
between databases. I don't believe your solution would be thread safe.
(2) I needed to handle getting the property name of a
column in a table in the Java class by only knowing
the field and table names (the physical database).
Since I wouldn't always know how every field might map
to a property name, I entered the looping to do a
match and then pull the property value with the
mapping.
http://cwiki.apache.org/confluence/pages/viewpage.action?pageId=73154
What is it you are wanting to do here? One of the primary purposes of
an ORM is to insulate the user from the database schema, allowing you
to refactor the database naming and schema without touching your Java
code. Hardcoding in database field names may not be in the best
interests of this approach. Also the comments in your example suggest
a one to one mapping between databases tables (DbEntity) and
ObjEntity. This is not always true in Cayenne:
http://cayenne.apache.org/doc/handling-inheritance.html
My apologizes for not placing these topics on the
correct pages of the wiki. I wasn't sure where they
might of fit, so I took a shot. Andrus mentioned maybe
on the FAQ pages.
Sure, and we certainly welcome your input (and anyone else who has
done interesting things with Cayenne).
Ari Maniatis
-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001 fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A