[4.0M3-SNAPSHOT] Modeller and UNSIGNED BIGINT

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[4.0M3-SNAPSHOT] Modeller and UNSIGNED BIGINT

fael
Hello all,

I was using Cayenne's baked in AUTO_PK_SUPPORT up till very recently.

Have now switched to use database-generated keys - I'm using the MySQL driver.

My keys are all defined in MySQL as BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT.

Foreign key fields are defined as BIGINT(20) UNSIGNED (sometimes NOT NULL).

I was really pleased to see that for new DbEntity items when I correctly set the PK Generation Strategy an 'AUTO_INCREMENT' is added to the generated SQL when migrating!!

I did hit a wall when trying to set a DbEntity attribute type to be specifically an UNSIGNED BIGINT; can't seem to do this and therefore can't use the modeller to migrate for my UNSIGNED BIGINT.

Even if this may not be something worth adding in - I wondered whether there was any way I might override or configure to achieve this.

Many thanks,
Peter


Reply | Threaded
Open this post in threaded view
|

Re: [4.0M3-SNAPSHOT] Modeller and UNSIGNED BIGINT

Andrus Adamchik
DbAttributes are limited to the set of types defined in JDBC spec. So Cayenne capabilities for generating DB schemas from Cayenne are necessarily limited as well unfortunately. We may consider adding DB-specific type hints to the model in the future... Something to think about.

Instead in 4.0 we started to focus heavily on DB-first flow and automating DB reverse-engineering. In M3 (and especially in M4 [1]) "cdbimport" is the king, and a workflow usually looks like this:

* You'd use a SQL migrations framework to bring a local DB to a certain version. This is outside of the scope of Cayenne and is done with a third-party tool such as Liquibase or Flyway.

* OR mapping model (Cayenne XML files) is synchronized with the state of the database using "cdbimport" provided by Cayenne.

* Object layer of the OR mapping model is customized to the developer liking, usually via CayenneModeler. Subsequent runs of "cdbimport" will not override any customizations that you make.

* Java classes are generated using "cgen" provided by Cayenne.

Andrus

[1] https://lists.apache.org/thread.html/50d174a15a6f10b22efd67439ad640eb803b829280148892809331a1@%3Cdev.cayenne.apache.org%3E

> On Oct 25, 2016, at 4:05 PM, fael <[hidden email]> wrote:
>
> Hello all,
>
> I was using Cayenne's baked in AUTO_PK_SUPPORT up till very recently.
>
> Have now switched to use database-generated keys - I'm using the MySQL
> driver.
>
> My keys are all defined in MySQL as BIGINT(20) UNSIGNED NOT NULL
> AUTO_INCREMENT.
>
> Foreign key fields are defined as BIGINT(20) UNSIGNED (sometimes NOT NULL).
>
> I was really pleased to see that for new DbEntity items when I correctly set
> the PK Generation Strategy an 'AUTO_INCREMENT' is added to the generated SQL
> when migrating!!
>
> I did hit a wall when trying to set a DbEntity attribute type to be
> specifically an UNSIGNED BIGINT; can't seem to do this and therefore can't
> use the modeller to migrate for my UNSIGNED BIGINT.
>
> Even if this may not be something worth adding in - I wondered whether there
> was any way I might override or configure to achieve this.
>
> Many thanks,
> Peter