persistence@glassfish.java.net

Re: Toplink is using a sequence for Microsoft SQL Server?

From: Mitesh Meswani <Mitesh.Meswani_at_Sun.COM>
Date: Wed, 29 Nov 2006 15:04:51 -0800

Jon Miller wrote:
> Hello all,
>
> Is there a way for me to subscribe to this list, or, is it only for
> Glassfish developers? I don't see a link to signup on the site.
You can subscribe from this
<https://glassfish.dev.java.net/servlets/ProjectMailingListList> page.
Please note that you need to be logged on to enable subscription.
>
> I'm just getting started using the standalone Toplink persistence
> provider and I have it working to a limited extent. However, I'm using
> Microsoft SQL Server and I see that it's generating a "SEQUENCE" table
> while I would have expected it to use an identity column instead. I've
> worked with Hibernate up until now and Hibernate has so called
> "dialects" that allow you to specify what DBMS SQL dialect to use.
> Does Toplink have this? I tried setting the GeneratorType to IDENTITY,
> but, it isn't working. It looks like it's trying to assign a random
> value to the id and SQL Server is rejecting it. Any help would be
> appreciated.
You need to use @GeneratedValue as shown in example below.

@Entity
public class Bar {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    .
    .
}

Regards,
Mitesh
> Jon