Hello *,
I'm usually using JDO with DataNucleus, but for a customer's project, I'm porting some of our existing data models to JPA with Hibernate. Thus I'm pretty new to JPA and maybe I made a mistake in my usage of @OneToMany, but I'm pretty sure that I found a bug in Hibernate.
Here's the situation (just a small & simplified excerpt):
Code:
public class RoleGroupRef
{
  @EmbeddedId
  private RoleGroupRefID objectID;
  @OneToMany
  @JoinTable(name="JFireBase_RoleGroupRef_authorizedObjectRefs")
  @MapKey(name="objectID.authorizedObjectID")
  private Map<String, AuthorizedObjectRef> authorizedObjectRefs = new HashMap<String, AuthorizedObjectRef>();
}
public class RoleGroupRefID extends AbstractObjectID
{
   @Column(length=100)
   private String organisationID;
   @Column(length=100)
   private String authorityID;
   @Column(length=100)
   private String roleGroupID;
}
public class AuthorizedObjectRef
{
  @EmbeddedId
  private AuthorizedObjectRefID objectID;
}
public class AuthorizedObjectRefID extends AbstractObjectID
{
  @Column(length=100)
  private String organisationID;
  @Column(length=50)
  private String authorityID;
  @Column(length=255)
  private String authorizedObjectID;
}
This leads to the following join-table:
CREATE TABLE  `test1`.`JFireBase_RoleGroupRef_authorizedObjectRefs` (
  `JFireBase_RoleGroupRef_authorityID` varchar(100) NOT NULL,
  `JFireBase_RoleGroupRef_organisationID` varchar(100) NOT NULL,
  `JFireBase_RoleGroupRef_roleGroupID` varchar(100) NOT NULL,
  `authorizedObjectRefs_authorityID` varchar(50) NOT NULL,
  `authorizedObjectRefs_authorizedObjectID` varchar(255) NOT NULL,
  `authorizedObjectRefs_organisationID` varchar(100) NOT NULL,
  PRIMARY KEY 
  (
  `JFireBase_RoleGroupRef_authorityID`,
  `JFireBase_RoleGroupRef_organisationID`,
  `JFireBase_RoleGroupRef_roleGroupID`,
  `authorizedObjectRefs_authorityID`,
  `authorizedObjectRefs_authorizedObjectID`,
  `authorizedObjectRefs_organisationID`
  ),
  UNIQUE KEY `authorizedObjectRefs_authorityID`
  (
  `authorizedObjectRefs_authorityID`,
  `authorizedObjectRefs_authorizedObjectID`,
  `authorizedObjectRefs_organisationID`
  ),
  KEY `FKA9642EC17F28764D` (`JFireBase_RoleGroupRef_authorityID`,`JFireBase_RoleGroupRef_organisationID`,`JFireBase_RoleGroupRef_roleGroupID`),
  KEY `FKA9642EC1818A1973` (`authorizedObjectRefs_authorityID`,`authorizedObjectRefs_authorizedObjectID`,`authorizedObjectRefs_organisationID`),
  CONSTRAINT `FKA9642EC1818A1973` FOREIGN KEY (`authorizedObjectRefs_authorityID`, `authorizedObjectRefs_authorizedObjectID`, `authorizedObjectRefs_organisationID`) REFERENCES `JFireBase_AuthorizedObjectRef` (`authorityID`, `authorizedObjectID`, `organisationID`),
  CONSTRAINT `FKA9642EC17F28764D` FOREIGN KEY (`JFireBase_RoleGroupRef_authorityID`, `JFireBase_RoleGroupRef_organisationID`, `JFireBase_RoleGroupRef_roleGroupID`) REFERENCES `JFireBase_RoleGroupRef` (`authorityID`, `organisationID`, `roleGroupID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8The red UNIQUE KEY is IMHO wrong. Why should I not be able to put the same 
AuthorizedObjectRef into multiple 
RoleGroupRef instances?
Now the question: Are my annotations at the field 
RoleGroupRef.authorizedObjectRefs wrong or is this a bug in Hibernate? If it's my fault, how do I annotate it correctly?
Best regards, Marco :-)