users@glassfish.java.net

Sanity check: does _at_TableGenerator need to "come before" _at_GeneratedValue?

From: Laird Nelson <ljnelson_at_gmail.com>
Date: Fri, 2 Sep 2011 18:14:32 -0400

We're getting some odd deployment errors after introducing a cartload of
@TableGenerator annotations on our entities.

Here's a snippet:

C:\glassfish3\bin>asadmin deploy C:\foo-ear-1.0-SNAPSHOT.ear
remote failure: Error occurred during deployment: Exception while preparing
the
app : Unknown Id.generator: State. Please see server.log for more details.
Command deploy failed.

The class that this error is most likely talking about is annotated like
this:

  @javax.xml.bind.annotation.XmlElement(name = "id")
  private long id;

  @javax.persistence.Access(javax.persistence.AccessType.PROPERTY)
  @javax.persistence.Column(name = "id")
  @javax.persistence.GeneratedValue(strategy =
javax.persistence.GenerationType.TABLE, generator = "State")
  @javax.persistence.Id
  @javax.persistence.TableGenerator(
    allocationSize = 500,
    initialValue = 100000,
    name = "State",
    pkColumnName = "sequence_name",
    pkColumnValue = "State",
    table = "jpa_sequence",
    valueColumnName = "last_value"
  )
  @Override
  protected long getId() {
    return this.id;
  }

find/grep yields no other generator named "State", and no other
@GeneratedValue annotation referencing a generator of name "State".

My first thought is this is (incredulously) order-related. Before I go and
waste some time on slapping test cases together and other things that don't
add value for our customers :-), I was hoping that someone right away could
say oh, yep, order is important in these annotations, or, no, the problem is
definitely going to be something else.

Best,
Laird

-- 
http://about.me/lairdnelson