Re: many-to-many mapping resulting in incomplete SQL queries

From: Michael Gentry (blacknex..mail.com)
Date: Mon May 12 2008 - 10:17:07 EDT

  • Next message: Andrus Adamchik: "Re: chaining and chunking"

    Hi Dan,

    I don't see anything offhand. Since you said you created a simple
    test application, could you send it to me and I'll take a look at it?
    Just tar it up and send directly to me (the mailing list doesn't
    support attachments). Be sure to sanitize the DB connection
    information first, though.

    Thanks,

    /dev/mrg

    On Fri, May 9, 2008 at 6:00 PM, Daniel Doppmeier
    <ddoppme..ebitec.uni-bielefeld.de> wrote:
    > Hi!
    > I'm sorry I made a mistake there. When I was posting the code I was leaving
    > out some lines of comment and I seem to have lost one line of code
    > meanwhile.
    >
    > So here is the (slightly changed) code again. This time free of typing
    > errors, I hope:
    >
    > DataContext context = DataContext.createDataContext();
    > // create a book
    >
    > Book book1 = (Book) context.newObject(Book.class);
    > book1.setTitle("The secret life of Donald D");
    >
    > // create a person
    >
    > Person author1 = (Person) context.newObject(Person.class);
    > author1.setName("Huey");
    > // asign person as author to the book
    > author1.addToBooks(book1);
    > // save objects to DB
    > context.commitChanges();
    > // remove the book from the author's list of book and commit
    > changes
    >
    > author1.removeFromBooks(book1);
    > context.commitChanges();
    >
    > The problem is still the same as described earlier.
    >
    >
    > Michael Gentry schrieb:
    >
    >
    >
    > > Hi Daniel, I'm not sure if you've solved your problem yet, but from
    > > the code you posted, I don't see where you established any
    > > relationship between book1 and author1/author2. You had objects with
    > > no relationship defined, so you can't actually remove book1 from
    > > author1.
    > >
    > > /dev/mrg
    > >
    > >
    > > On Tue, May 6, 2008 at 4:17 AM, Daniel Doppmeier
    > > <ddoppme..ebitec.uni-bielefeld.de> wrote:
    > >
    > >
    > > > Hello everyone!
    > > >
    > > > I am new to cayenne and experiencing some problems, when modelling a
    > > > many-to-many relationship. After I could not solve the problem for an
    > > > application I am writing at the moment, I set up the following example
    > > > application, which is producing the same problems:
    > > >
    > > > I modelled a small bookstore application, with two tables "Book" and
    > > > "Person". After that I created a join table "Person_is_author_of_book",
    > to
    > > > map from "Person" entries to "Book" entries. On the object side of the
    > > > application, this would mean, that every book may have several authors,
    > > > whereas one author may have written more than one book.
    > > >
    > > > Inserting and fetching data from the DB seems to work just fine, but
    > when it
    > > > comes to deletion there occures my problem. This is what happens in my
    > code:
    > > >
    > > > DataContext context = DataContext.createDataContext();
    > > > Book book1 = (Book) context.newObject(Book.class);
    > > > book1.setTitle("The secret life of Donald D");
    > > >
    > > > Person author1 = (Person) context.newObject(Person.class);
    > > > author1.setName("Huey");
    > > > Person author2 = (Person) context.newObject(Person.class);
    > > > author2.setName("Dewey");
    > > >
    > > > context.commitChanges();
    > > >
    > > > author1.removeFromBooks(book1);
    > > > context.commitChanges();
    > > >
    > > > Everything is fine until the second commitChanges(), when I try to
    > delete
    > > > book1 from author1's list.
    > > > This is what the logger says about it:
    > > >
    > > > INFO QueryLogger: --- will run 1 query.
    > > > INFO QueryLogger: --- transaction started.
    > > > INFO QueryLogger: DELETE FROM Person_is_author_of_book WHERE
    > > > INFO QueryLogger: *** error.
    > > >
    > > > As you can see, there is missing some SQL syntax after the WHERE clause.
    > > > Does anybody have an idea, what may cause this malformed SQL?
    > > >
    > > > I am using the latest stable cayenne version 2.0.4, MySQL
    > 5.0.51a-3ubuntu5
    > > > and java "1.6.0_06"
    > > >
    > > >
    > > > Thanks a lot for any help!
    > > >
    > > >
    > > >
    > > >
    > >
    > >
    > >
    >



    This archive was generated by hypermail 2.0.0 : Mon May 12 2008 - 10:17:44 EDT