FAQ
I successfully re-engineered a database.

Now I like to insert a record into a table that has a primary key of two
columns: one integer that is actually a foreign key and a Date value.

Is there somewhere an example similar to my task?

Thank you for your help.

Kind regards


Rolf

Search Discussions

  • Andrus Adamchik at Jan 8, 2012 at 2:02 pm
    Hi Rolf,

    For FK column, map a relationship from another table, and check "To Dep PK" for that relationship [1]. This will ensure that the value of PK column that is also an FK will be set from the related PK.

    For the Date PK column, map it as an ObjAttribute and set it yourself as you would set any other object property.

    Cheers,
    Andrus


    [1] http://cayenne.apache.org/doc30/to-dep-pk-checkbox.html
    On Jan 8, 2012, at 2:34 AM, mailinglist wrote:

    I successfully re-engineered a database.

    Now I like to insert a record into a table that has a primary key of two columns: one integer that is actually a foreign key and a Date value.

    Is there somewhere an example similar to my task?

    Thank you for your help.

    Kind regards


    Rolf
  • Mailinglist at Jan 11, 2012 at 2:16 pm
    I got the failure

    java.sql.SQLException: No rows for 'MY_TABLE"

    on commit.

    What I did:

    read in the whole MY_TABLE (draws some other objects from n:1 relations).
    updated a few objects.
    added a few new objects to the context for MY_TABLE.

    issued the commit and got the failure.

    Now I need some help how to go further in order to pinpoint the cause.

    Kind regards


    Rolf
  • Aristedes Maniatis at Jan 11, 2012 at 11:00 pm

    On 12/01/12 1:16 AM, mailinglist wrote:
    I got the failure

    java.sql.SQLException: No rows for 'MY_TABLE"

    on commit.

    What I did:

    read in the whole MY_TABLE (draws some other objects from n:1 relations).
    updated a few objects.
    added a few new objects to the context for MY_TABLE.

    issued the commit and got the failure.

    Now I need some help how to go further in order to pinpoint the cause.

    Kind regards


    Rolf
    Perhaps you could post a few lines of your code. But first reduce your code to just do one thing: fetch a record, update it and commit again.

    Ari




    --
    -------------------------->
    Aristedes Maniatis
    GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
  • Ngong at Jan 13, 2012 at 6:47 am
    Thank you Ari for your kind offer.

    I reduced the problem to the bare minimum and the error remains.

    If you may you can download it from august.de/testCayenne.zip, e.g. by

    wget august.de/testCayenne.zip

    You will find the Main.java.
    There is also a README.txt where I explained how I produced my error.

    Kind Regards


    Rolf

    --
    View this message in context: http://cayenne.195.n3.nabble.com/new-to-cayenne-tp3650719p3655208.html
    Sent from the Cayenne - User mailing list archive at Nabble.com.
  • Aristedes Maniatis at Jan 14, 2012 at 6:10 am
    Hi Rolf (ngong)

    I think you over-judged the kindness of my offer :-) Sorry, but I don't have time to download your whole project and debug it. However, if you send to this mailing list the steps you are stuck on and a couple of lines of code, then I or someone else might have some ideas which will help you.

    Have you tried working your way through the tutorial on the website? That is probably the best place to start with understanding how to fetch and commit records.

    Ari

    On 13/01/12 9:47 AM, ngong wrote:
    Thank you Ari for your kind offer.

    I reduced the problem to the bare minimum and the error remains.

    If you may you can download it from august.de/testCayenne.zip, e.g. by

    wget august.de/testCayenne.zip

    You will find the Main.java.
    There is also a README.txt where I explained how I produced my error.

    Kind Regards


    Rolf

    --
    View this message in context: http://cayenne.195.n3.nabble.com/new-to-cayenne-tp3650719p3655208.html
    Sent from the Cayenne - User mailing list archive at Nabble.com.
    --
    -------------------------->
    Aristedes Maniatis
    GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
  • Ngong at Jan 14, 2012 at 9:45 am
    Fair enough, Ari.

    (however, I tried to be as nice as possible, reduced the project to just a
    few lines. Nothing extra in there, just the code producing the error.)

    Yes, I went through the tutorial, step by step and I take it as a reference
    while developing. It worked out fine. Thank you for that valueable
    introduction.
    (My goal is to take an existing schema ( http://ehour.nl/ http://ehour.nl/ )
    of a time tracking application and add records to it that I collected with
    my smart phone.)

    To run my test that leads to the error I have Eclipse with m2e and mysql
    installed.

    Create a database:
    mysql -u<user> -p<password>
    mysql>CREATE DATABASE eHour;
    mysql>quit

    Import the tables:
    mysql -u<user> -p<password> eHour <eh.dump

    Run As: Maven generate-sources
    Run As: Maven test

    The pom.xml: &lt;a
    href=&quot;http://paste.pocoo.org/show/534617/&quot;>http://paste.pocoo.org/show/534617/
    The Cayenne xml: http://paste.pocoo.org/show/534618/
    http://paste.pocoo.org/show/534618/
    The map.xml: http://paste.pocoo.org/show/534619/
    http://paste.pocoo.org/show/534619/
    The Java code: http://paste.pocoo.org/show/534620/
    http://paste.pocoo.org/show/534620/

    The code is very simple: It reads in all timesheet entries as of a certain
    date (in order to make sure not to enter something twice, but that is
    exchanged just by a printout here).

    The PK of a timesheet entry is made of two columns: a date and a FK of a
    project assignment (actually a relation between a project and a user).

    To make sure that a foreign record exists in the example here I just took a
    project assignment from the first timesheet entry I had read in.

    Commiting that newly created timesheet record leads to the error:
    http://paste.pocoo.org/show/534625/ http://paste.pocoo.org/show/534625/

    With this consol output: http://paste.pocoo.org/show/534627/
    http://paste.pocoo.org/show/534627/



    I am pretty sure that the source of my error is somthing simple I have
    ovelooked. However, as I have no clue where to look and what to do next (I
    googled and searched on Cayenne pages a lot) I provide you all information
    that may be need. Sorry for the amount.

    Kind Regards


    Rolf




    --
    View this message in context: http://cayenne.195.n3.nabble.com/new-to-cayenne-tp3650719p3658627.html
    Sent from the Cayenne - User mailing list archive at Nabble.com.
  • Aristedes Maniatis at Jan 16, 2012 at 10:58 am
    Sometimes I get confused looking at the XML, but it looks like you are specifying that the join to the ProjectAssignment is to a primary key of that table, when actually it isn't. Try unticking the "toDependentPK" checkbox. You usually want that ticked in one direction but not the other. You have a compound key in the ProjectAssignment table.

    Ari

    On 14/01/12 8:44 PM, ngong wrote:
    Fair enough, Ari.

    (however, I tried to be as nice as possible, reduced the project to just a
    few lines. Nothing extra in there, just the code producing the error.)

    Yes, I went through the tutorial, step by step and I take it as a reference
    while developing. It worked out fine. Thank you for that valueable
    introduction.
    (My goal is to take an existing schema ( http://ehour.nl/ http://ehour.nl/ )
    of a time tracking application and add records to it that I collected with
    my smart phone.)

    To run my test that leads to the error I have Eclipse with m2e and mysql
    installed.

    Create a database:
    mysql -u<user> -p<password>
    mysql>CREATE DATABASE eHour;
    mysql>quit

    Import the tables:
    mysql -u<user> -p<password> eHour<eh.dump

    Run As: Maven generate-sources
    Run As: Maven test

    The pom.xml:&lt;a
    href=&quot;http://paste.pocoo.org/show/534617/&quot;>http://paste.pocoo.org/show/534617/
    The Cayenne xml: http://paste.pocoo.org/show/534618/
    http://paste.pocoo.org/show/534618/
    The map.xml: http://paste.pocoo.org/show/534619/
    http://paste.pocoo.org/show/534619/
    The Java code: http://paste.pocoo.org/show/534620/
    http://paste.pocoo.org/show/534620/

    The code is very simple: It reads in all timesheet entries as of a certain
    date (in order to make sure not to enter something twice, but that is
    exchanged just by a printout here).

    The PK of a timesheet entry is made of two columns: a date and a FK of a
    project assignment (actually a relation between a project and a user).

    To make sure that a foreign record exists in the example here I just took a
    project assignment from the first timesheet entry I had read in.

    Commiting that newly created timesheet record leads to the error:
    http://paste.pocoo.org/show/534625/ http://paste.pocoo.org/show/534625/

    With this consol output: http://paste.pocoo.org/show/534627/
    http://paste.pocoo.org/show/534627/



    I am pretty sure that the source of my error is somthing simple I have
    ovelooked. However, as I have no clue where to look and what to do next (I
    googled and searched on Cayenne pages a lot) I provide you all information
    that may be need. Sorry for the amount.

    Kind Regards


    Rolf




    --
    View this message in context: http://cayenne.195.n3.nabble.com/new-to-cayenne-tp3650719p3658627.html
    Sent from the Cayenne - User mailing list archive at Nabble.com.
    --
    -------------------------->
    Aristedes Maniatis
    GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
  • Ngong at Jan 18, 2012 at 9:02 am
    Hi, Ari

    thank you for your answer.

    I have got the xml using the modeler and reverse engineering the eHour
    database (a mysql dump file is included in august.de/testCayenne.zip). Maybe
    there are some options I got to choose different. I will check that.

    If you know hints on limitations to the reverse engineering tool please drop
    me a note.

    Kind Regards

    Rolf

    --
    View this message in context: http://cayenne.195.n3.nabble.com/new-to-cayenne-tp3650719p3668672.html
    Sent from the Cayenne - User mailing list archive at Nabble.com.
  • Andrus Adamchik at Jan 19, 2012 at 7:55 am
    Haven't looked at the actual model yet, but certainly reverse engineering is just a starting point. The quality of reverse engineering depends on the quality of the DB schema, constraints, consistent naming, etc. Also you may want to remap certain defaults (e.g. adding flattened relationships over some tables, etc.) So doing a manual pass and tweaking over a reverse-engineered model is always a good idea.

    Cheers,
    Andrus
    On Jan 18, 2012, at 12:01 PM, ngong wrote:

    Hi, Ari

    thank you for your answer.

    I have got the xml using the modeler and reverse engineering the eHour
    database (a mysql dump file is included in august.de/testCayenne.zip). Maybe
    there are some options I got to choose different. I will check that.

    If you know hints on limitations to the reverse engineering tool please drop
    me a note.

    Kind Regards

    Rolf

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedJan 7, '12 at 11:34p
activeJan 19, '12 at 7:55a
posts10
users4
websitecayenne.apache.org

People

Translate

site design / logo © 2022 Grokbase