-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Spurious composite-id class warnings ?
PostPosted: Fri May 06, 2016 10:08 am 
Newbie

Joined: Fri May 06, 2016 9:32 am
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.