Apparently modelling a simple parent child relationship where the primary key of the parent is part of a composite key on the child is not possible using EJB3 annotations.

For enterprise beans this seems like a very large oversight. I know a couple of projects that use this idiom for their relational structures. It feels odd that this is not part of the current implementation of the EJB3 annotations. For those trying out Hibernate, here is a forum post regarding this problem.

The problem I am facing is in my opinion a very basic mapping case. It seems strange and very limiting that it is not part of the annotations.

For those that don't get what I am referring to, consider the following:

@Entity
public class Parent {
    @Id
    Long id;

    @OneToMany
    @JoinColumn(name = "parent")
    List children;
}

@Entity
public class Child {
    @ManyToOne()
    @JoinColumn(nullable = false, insertable = false, updatable = false, name = "parent")
    Parent parent;

    Long childNr;
}

Now try to make both the parent and the childNr part of the primary key of the child using annotations.

And what seems even worse, is that you need to define a composite key class especially for using a composite key. Apparently that is needed for sending over the object's key across the network.

Annotations are very useful, and we have been able to build large parts of our system using them. So don't see this as a rejection of the technology as a whole. I enjoy working with annotations for mapping purposes but they just don't seem to be quite there yet.