FAQ
Hi,i have configured a simple cayenne datamap for my application with 2
table.
All works fine, i can read/write into them without problem.

Now, i want to create at runtime the database schema, so if is the first
time and the database is empty i can generate it on the fly.
I do it with this code (taken from petstore sample in cayenne's wiki):


DataDomain domain =
Configuration.getSharedConfiguration().getDomain();

DataNode node = getDataNode(domain);
DbGenerator generator = new DbGenerator(node.getAdapter(),
getDataMap(domain));
try {
generator.runGenerator(node.getDataSource());
} catch (Exception e) {
throw new Exception("Error generating DB schema", e);
}

If i test this code on a HSQLDB it works well.
The strange thing is that after execution i have 3 tables instead of 2...
infact there is also "AUTO_PK_SUPPORT" that i haven't defined in my datamap.
I suppose that it is a table used by canyenne.

But if i test it on MYSQL db it doesn't work.
ONLY the "AUTO_PK_SUPPORT" is created.

Anyone have idea why the same code works in 2 different way?

The user that i use to connect to mysql haves all privileges.


Thanks
Davide

Search Discussions

  • Michael Gentry at Jan 14, 2009 at 2:59 pm
    The AUTO_PK_SUPPORT table is a "hidden" table used by Cayenne for some, but
    not all, databases. For a database that doesn't support sequences (Oracle
    and PostgreSQL do) or auto-increment (MySQL does), then Cayenne will fall
    back to using the AUTO_PK_SUPPORT table to help it generate primary keys for
    inserts.
    I'm not sure offhand why you'd see your tables with HSQLDB, but not MySQL.
    I'm assuming you are programmatically setting the JDBC driver and URL
    elsewhere and are using the default DB Adapter (which tries to guess which
    one to actually use)?


    On Wed, Jan 14, 2009 at 8:46 AM, mr. abanjo wrote:

    Hi,i have configured a simple cayenne datamap for my application with 2
    table.
    All works fine, i can read/write into them without problem.

    Now, i want to create at runtime the database schema, so if is the first
    time and the database is empty i can generate it on the fly.
    I do it with this code (taken from petstore sample in cayenne's wiki):


    DataDomain domain =
    Configuration.getSharedConfiguration().getDomain();

    DataNode node = getDataNode(domain);
    DbGenerator generator = new DbGenerator(node.getAdapter(),
    getDataMap(domain));
    try {
    generator.runGenerator(node.getDataSource());
    } catch (Exception e) {
    throw new Exception("Error generating DB schema", e);
    }

    If i test this code on a HSQLDB it works well.
    The strange thing is that after execution i have 3 tables instead of 2...
    infact there is also "AUTO_PK_SUPPORT" that i haven't defined in my
    datamap.
    I suppose that it is a table used by canyenne.

    But if i test it on MYSQL db it doesn't work.
    ONLY the "AUTO_PK_SUPPORT" is created.

    Anyone have idea why the same code works in 2 different way?

    The user that i use to connect to mysql haves all privileges.


    Thanks
    Davide
  • Mr.abanjo at Jan 14, 2009 at 6:00 pm
    HI Michael,thanks for your answer!
    I found the problem... was my fault!
    Both the tables have a filed named "key" and in mysql this keyword is
    "protected".
    This is the reason for the different behaviour on mysql and hsqldb.
    ;-)

    Thanks again.
    Davide
    On Wed, Jan 14, 2009 at 3:59 PM, Michael Gentry wrote:

    The AUTO_PK_SUPPORT table is a "hidden" table used by Cayenne for some, but
    not all, databases. For a database that doesn't support sequences (Oracle
    and PostgreSQL do) or auto-increment (MySQL does), then Cayenne will fall
    back to using the AUTO_PK_SUPPORT table to help it generate primary keys
    for
    inserts.
    I'm not sure offhand why you'd see your tables with HSQLDB, but not MySQL.
    I'm assuming you are programmatically setting the JDBC driver and URL
    elsewhere and are using the default DB Adapter (which tries to guess which
    one to actually use)?


    On Wed, Jan 14, 2009 at 8:46 AM, mr. abanjo wrote:

    Hi,i have configured a simple cayenne datamap for my application with 2
    table.
    All works fine, i can read/write into them without problem.

    Now, i want to create at runtime the database schema, so if is the first
    time and the database is empty i can generate it on the fly.
    I do it with this code (taken from petstore sample in cayenne's wiki):


    DataDomain domain =
    Configuration.getSharedConfiguration().getDomain();

    DataNode node = getDataNode(domain);
    DbGenerator generator = new DbGenerator(node.getAdapter(),
    getDataMap(domain));
    try {
    generator.runGenerator(node.getDataSource());
    } catch (Exception e) {
    throw new Exception("Error generating DB schema", e);
    }

    If i test this code on a HSQLDB it works well.
    The strange thing is that after execution i have 3 tables instead of 2...
    infact there is also "AUTO_PK_SUPPORT" that i haven't defined in my
    datamap.
    I suppose that it is a table used by canyenne.

    But if i test it on MYSQL db it doesn't work.
    ONLY the "AUTO_PK_SUPPORT" is created.

    Anyone have idea why the same code works in 2 different way?

    The user that i use to connect to mysql haves all privileges.


    Thanks
    Davide

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedJan 14, '09 at 1:47p
activeJan 14, '09 at 6:00p
posts3
users2
websitecayenne.apache.org

2 users in discussion

Mr.abanjo: 2 posts Michael Gentry: 1 post

People

Translate

site design / logo © 2022 Grokbase