Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl-generator: Identity for PK is always generated #3399

Closed
magicprinc opened this issue May 9, 2024 · 5 comments
Closed

ddl-generator: Identity for PK is always generated #3399

magicprinc opened this issue May 9, 2024 · 5 comments

Comments

@magicprinc
Copy link

magicprinc commented May 9, 2024

I generate ID in my App in java code, so my id column is declared in entity class as:

@Id
Long id;

but DdlGenerator generates such columns as:
id bigint identity(1,1) not null,
instead of expected:
id bigint not null,

MSSQL doesn't allow then insert values into column id, because id is an identity column.

The same is true for MySQL (identity related keywords are added).

see
io.ebeaninternal.dbmigration.model.MTableIdentity#fromCreateTable
io.ebeaninternal.dbmigration.ddlgeneration.platform.BaseTableIdentity#identity

@rob-bygrave
Copy link
Contributor

Use ebean.idGeneratorAutomatic=false or set it via DatabaseConfig.setIdGeneratorAutomatic(false)

This defaults to true and means that @Id properties use either Identity or Sequence based on the DatabasePlatform. Turning this off means that when those are needed an explicit @GeneratedValue is required.

@rob-bygrave
Copy link
Contributor

The above globally turns off ebeans implicit behaviour. An alternative for the case that MOST entities use Identity or Sequence and only a few are application controlled identity values, then we can use ebean specific @Identity(type=APPLICATION) so:

@Id @Identity(type=APPLICATION)
Long id;

@magicprinc
Copy link
Author

I love your project. You have everything: beyond anyone could dream of 🤝🔥

I have recently modernized a legacy project. And among other things, I have replaced jOOQ by Ebean. The code is more concise and readable now.

@rob-bygrave
Copy link
Contributor

Thanks for that, it's great getting feedback. There is some missing documentation on this which should be added at: https://ebean.io/docs/mapping/jpa/id#generated-value ... so I'll look to do that.

Cheers, Rob.

@rbygrave
Copy link
Member

Ok, I've update the website documentation. We can close this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants