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

Hmm... I will probably just use TABLE then, since I've also read
somewhere on this list that it might be faster, because ids can be
pre-allocated. Or maybe even some form of UUIDs.

On Wed, May 20, 2009 at 3:13 PM, Gordon Yorke <gordon.yorke@xxxxxxxxxx> wrote:
> 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
>>
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>


Back to the top