[jboss-user] [EJB 3.0] - Re: Attribute from MappedClass as a part of composit PK ?

Wolfgang Knauf do-not-reply at jboss.com
Mon Jun 22 08:14:55 EDT 2009


Hi Dalibor,

one more idea, which might prevent you from duplicating the fields:

Instead of an EmbeddedId, use an IdClass (annotate the entity with "IdClass"). This class will have the same fields as the EmbeddedId, but no further annotations.
All primary key fields are part of your entity. The timestamp property has to be copied to the subclass, best with an @Override annotation, and getter/setter just call the base class methods.

Here is a snippet:

  | public class MyId implements Serializable
  | {
  |   public TimeStamp getSomething()
  |   {
  |     ...
  |   }
  |   public Integer getOtherIdFields()
  |   {
  |     ...
  |   }
  | }
  | 
  | @IdClass(value=MyId.class)
  | public MyEntity extends BaseEntity implements Serializeable
  | {
  |   @Id
  |   @Override
  |   public TimeStamp getSomething()
  |   {
  |     return super.getSomething();
  |   }
  |   ...setter...
  | 

The ID class is required to make "entityManager.find" work, and inserting of entities will not work without. So you need the ID class even if your code does not need it.

Hope this helps (and works ;-) )

Wolfgang

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4239066#4239066

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4239066



More information about the jboss-user mailing list