Hello!
I think I have found a case where hibernate throws spurious/misleadings warnings when using shared primary keys.
I have two tables with a shared primary key, where the PK for UserDetail is also a foreign key to UserEntity:
Code:
CREATE TABLE `UserEntity` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) COLLATE utf8_hungarian_ci DEFAULT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `UserDetail` (
`userId` int(11) NOT NULL, --FK to UserEntity
`detail` varchar(100) COLLATE utf8_hungarian_ci DEFAULT NULL,
PRIMARY KEY (`userId`)
);
And the entities for them:
Code:
@Entity
public class UserDetail implements Serializable {
@Id
@OneToOne
@JoinColumn(name = "userId")
UserEntity user;
String detail;
// getters, setters omitted
// hashCode, equals omitted
}
Code:
@Entity
public class UserEntity implements Serializable {
@Id
private int id;
private String name;
// getters, setters omitted
// hashCode, equals omitted
}
When both entites have hashCode() and equals() method defined, hibernate starts up without warnings.
If I remove the hashCode() and equals() methods from the UserDetail entity, Hibernate throws the following warnings at startup:
Code:
15:24:37,150 WARN [org.hibernate.mapping.RootClass] (ServerService Thread Pool -- 324) HHH000038: Composite-id class does not override equals(): testcase.UserDetail
15:24:37,150 WARN [org.hibernate.mapping.RootClass] (ServerService Thread Pool -- 324) HHH000039: Composite-id class does not override hashCode(): testcase.UserDetail
Strangely, if I remove the hashCode and equals methods from the UserEntity entity, I get no warnings.
Strictly speaking, I did not explicitly define any Composite id classes, but I can accept that the shared primary keys feature is internally implemented with composite ids.
However, even then I would expect hibernate to throw warnings when the referred class (UserEntity) is missing the hashCode/equals methods, not when the referring class does, which is not used as a PK anywhere.
I am porting my application over from EclipseLink, which does not have a problem with similar entites.
Did I find a bug or do I completely misunderstand the problem ?
My test environment is Wildfly 10.0 final.