Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Id column settable both automatically and manually

I suspect you will have to file an enhancement request. Manually assigning id's will work for Table based sequencing and Sequence object sequencing but with IDENTITY sequencing EclipseLink must not be checking the id value before choosing to send the insert.
--Gordon

Jaka Jančar wrote:
Hi,

I'm using MySQL and have the following entity:

class MyEntity {
  @Id
  @GeneratedValue(strategy=IDENTITY)
  @Column(name="id")
  private Integer id;
}

However, I would still like to be able to set the id manually!


The problem is that INSERT will never insert the id column. E.g., when
doing this:

  MyEntity e = new MyEntity();
  e.setId(15);
  em.persist(e);
  em.flush();
  em.refresh(e);

The following queries will be made:

INSERT INTO myEntities (col1, col2, col3) VALUES (?, ?, ?)
SELECT id, col1, col2, col3 FROM myEntities WHERE (id = 15)

And thus the id will still be auto-generated and the refresh() will
result in EntityNotFoundException.

If I don't set @GeneratedValue at all, then this case will work OK,
but when the value is autogenerated, LAST_INSERT_ID() won't be called.

Is it at all possible to have id columns settable both manually and
automatically, like in MySQL?

Regards,
Jaka
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top