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
generator
param of @GeneratedValue
is not ignored when using GenerationType.AUTO
on db where this uses identity
#2915
Comments
I've already created a google group discussion for this here with some reasoning about why we need this kind of behavior, but I've noticed the discussions created after October 10th haven't gotten any answers and I also think this is a bug, because of the inconsistency between explicit IDENTITY strategy and the AUTOmatically chosen one. |
…ignored when using GenerationType.AUTO on db where this uses identity
In the test it fails regardless of the DB Identity preference. That is, for That is, there is NO use of the database platform preferred identity/sequence at this stage - that happens much later in Really it looks like 2 paths to make it work:
Did you try just removing the |
Hi and thanks for the reply. Yeah, it does indeed work if I remove the |
Well, when using Ebean it isn't referenced by this param so the below works as we'd desire. However, with JPA it really suggests that it is referenced this way. So the fact that Ebean want's us to NOT have the generator referenced is kind-of-the-bug-here. So this below without the @Entity
@Table(name = "T_OBJECT")
public class EaObject extends Model {
@Id
@Column(name = "OBJECT_ID", nullable = false)
@GeneratedValue(
strategy = GenerationType.AUTO
)
@SequenceGenerator(
name = "t_object_sequence_generator",
sequenceName = "FRED_OBJECT_ID_SEQ"
)
long id;
final String name;
...
} With a DB with SEQUENCE as it's preferred strategy we get: create table T_OBJECT (
OBJECT_ID bigint not null,
name varchar(255),
constraint pk_t_object primary key (OBJECT_ID)
);
create sequence FRED_OBJECT_ID_SEQ start with 1 increment by 1; And to stress the point using @Id
@Column(name = "OBJECT_ID", nullable = false)
@GeneratedValue(
strategy = GenerationType.AUTO
)
@SequenceGenerator(
name = "THIS_NAME_IS_SILLY"
,sequenceName = "BOB_OBJECT_ID_SEQ"
)
long id; create table T_OBJECT (
OBJECT_ID bigint not null,
name varchar(255),
constraint pk_t_object primary key (OBJECT_ID)
);
create sequence BOB_OBJECT_ID_SEQ start with 1 increment by 1; Noting that the JPA identity/sequence annotations are less than ideal* in a few ways which is why Ebean also has it's own @Id
@Column(name = "OBJECT_ID", nullable = false)
@Identity(sequenceName = "KATIE_OBJECT_ID_SEQ")
long id; create table T_OBJECT (
OBJECT_ID bigint not null,
name varchar(255),
constraint pk_t_object primary key (OBJECT_ID)
);
create sequence KATIE_OBJECT_ID_SEQ increment by 1; * JPA identity/sequence annotations are less than ideal
In Review:JPA annotations really suggest we need the The fix is to remove that check and let it flow through to then assign the database platform default identity/sequence etc. |
…n using GenerationType.AUTO on db where this uses identity
#2915 - Failing test for - generator param of @GeneratedValue is not ignored when using GenerationType.AUTO on db where this uses identity
Hi, Cheers again for this great ORM, it really makes my life as a developer much more pleasant. |
Expected behavior
When
strategy = GenerationType.IDENTITY
is used, the@SequenceGenerator
annotation and thegenerator
parameter of@GeneratedValue
annotation is ignored, which is a good thing, because these don't actually make much sense when not using sequences. I think the behavior should be the same if you usestrategy = GenerationType.AUTO
on a db that choosesIDENTITY
as the strategy.Actual behavior
If you use
GenerationType.AUTO
on a db that choosesIDENTITY
as the strategy (so basically any db except Oracle) the@SequenceGenerator
annotation is correctly ignored, but thegenerator
param of@GeneratedValue
is not, resulting in the"No custom IdGenerator registered with name <specified generator name>"
exception.Steps to reproduce
Define an entity like this and use it in a db which chooses the IDENTITY strategy for
GenerationType.AUTO
The text was updated successfully, but these errors were encountered: