Skip to content


some notes on hibernate-annotation

I am now implementing my persistence layer with a vengence. I decided to take a chance with using the hibernate-annotation to define my persistence objects because of all the work with Seam and Trails that is happening to leverage those annotations.

Unfortunately, I got to experience the joys of being a trailblazer with CR code as opposed to released code. These are some of the issues I ran into with the hibernate-annotation 3.2.cr1 release:

The biggest problem so far is with compound primary keys. (keys that are composed of multiple fields). I wanted to create a @Entity class that had a compound field that was partially generated using the @GenerateValue flag and partially supplied with an application-defined value.

These are the problems I ran into:

  1. If you have a @Entity that has two or more fields annotated with @Id *and* @IdClass is not used,  then only the first one is respected. So the primary key is only the first field. However, all such fields are labeled as requiring a value (as if @NotNull specified). I filed this report about this problem.
  2. If using you do use @IdClass then the @Ids are respected with regards to the primary key definition. However, @GenerateValue is ignored when placed on @Embeddable’s (supplied in the @IdClass) fields. This makes sense for a bunch of reasons. The best one being that the @Embeddable may be used by multiple @Entity classes. Unfortunately, @GenerateValue is also ignored when placed on the @Entity class’s id fields.
  3. Using @EmbeddedId doesn’t have any mechanism for specifying a @GeneratedValue. And once again, @GenerateValue is ignored when placed on the @Embeddable class’ fields.
  4. When using @EmbeddedId, if @Id is used on the @Embeddable class’ fields this causes an error message that is completely wrong. 3.2.0.cr1 reports that the @Embeddable doesn’t have id fields. The problem is solved by removing the @Id’s, not by using them. I filed this report.

Now that I am passed these issues, I still don’t know how to create a compound key with part of it generated. So I posted this on the hibernate forums.

Posted in help notes.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.