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

Changes in DerbyAdaptor identity #233

Open
csnemeti opened this issue Dec 29, 2014 · 4 comments
Open

Changes in DerbyAdaptor identity #233

csnemeti opened this issue Dec 29, 2014 · 4 comments
Assignees
Milestone

Comments

@csnemeti
Copy link

Hello,

Right now identities for Derby are generated with
GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1).
I would like to suggest the following changes that could be made based on some system variables or some Batoo configuration variables:

  • Possibility to use GENERATED ALWAYS AS IDENTITY or GENERATED BY DEFAULT AS IDENTITY.
  • Possibility to define start value (default would be 1).
  • Possibility to define increment value (default would be 1).

I think these changes are important since they can help a lot in unit testing. When I re-import again the data in DB it always generates me new value for ID because of ALWAYS.

@asimarslan
Copy link
Contributor

Hi @csnemeti ,

I think we can add the identity sql part as a parameter from the code snippet;

    public String createColumnDDL(AbstractColumn column) {
        final boolean identity = column.getIdType() == IdType.IDENTITY;

        return column.getName() + " " // name part
            + this.getColumnType(column, column.getSqlType()) // data type part
            + (!column.isNullable() ? " NOT NULL" : "") // not null part
            + (column.isUnique() ? " UNIQUE" : "") // not null part
            + (identity ? " GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1)" : ""); // auto increment part
    }

I'm adding it to the next release

@asimarslan asimarslan added this to the 2.0.1.3 milestone Dec 29, 2014
@asimarslan asimarslan self-assigned this Dec 29, 2014
@csnemeti
Copy link
Author

Yes... I can help you with the code if you want...

@asimarslan
Copy link
Contributor

A pull request will be appreciated. Thanks.

@csnemeti
Copy link
Author

I will need some of your advice to implement this...
Adaptors have no configuration, while this one might require some... I see the following ways of doing this:

  1. Use the EntityManagerFactoryImpl#properties to provide configuration (and they can be set in persistence.xml).
  2. Use some System variables to provide the configuration values.
  3. Both...
  4. Create your own annotation to configure this like a sequence.

The thing with these identities in some database is that they act as a configurable sequence over a table. JPA has nothing to give you for configuring this so you should do this somehow.
Given this issue, I think you should decide how the implementation should proceed.

Q1: Should I fork the project and implemented there or create a branch here?
Q2: Should a start from master or a specific branch?

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

No branches or pull requests

2 participants