Service Builder: Overriding toCompare generates wrong codeService Builder: Overriding toCompare generates wrong codehttps://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=568507802024-03-29T06:49:49Z2024-03-29T06:49:49ZRE: Service Builder: Overriding toCompare generates wrong codeEnrique Valdes Lacasahttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1180633732019-12-12T15:59:34Z2019-12-12T15:59:34ZThanks for the quick reply David. I'll follow that approach.Enrique Valdes Lacasa2019-12-12T15:59:34ZRE: Service Builder: Overriding toCompare generates wrong codeDavid H Nebingerhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1180659062019-12-12T12:45:53Z2019-12-12T12:45:53ZYou are free to add methods to your model classes. So you could add a "compareToLimited()" sort of thing that implements what you want and then leverage it the way you want to.<br /><br /><br />You just shouldn't override the java methods.David H Nebinger2019-12-12T12:45:53ZRE: Service Builder: Overriding toCompare generates wrong codeEnrique Valdes Lacasahttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1180587172019-12-11T23:23:20Z2019-12-11T23:23:20ZThanks everyone for the feedback. I ran into the same question that this thread proposes, so I'm glad I found it. Now, since David pointed out that <em>"You can't and really shouldn't override the equals() and compareTo() methods."</em>...my question is: <br />Is there a preferred way in Liferay (and maybe within the Service Builder code) for comparing objects other than, for example, going field by field checking their value?<br />Thanks beforehand.Enrique Valdes Lacasa2019-12-11T23:23:20ZRE: Service Builder: Overriding toCompare generates wrong codeSotoku Alekidohttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=568688492015-07-29T13:03:34Z2015-07-29T13:03:34Z<div class="quote-title">David H Nebinger:</div><blockquote><div class="quote-title">Sototu Alekido:</div><blockquote>In the generated {Entityname}Impl.java classes I override the methods equals(Object object) and compareTo({Entityname} entity). After the regeneration, the classes {Entityname}Clp.java and {Entityname}Wrapper.java have the methods equals and compareTo each two times defined which of course throws a duplicated methode exception.<br /><br />Is there a solution for this or do I have to take the compareTo and equals methods the service builder is forcing me to use?</blockquote><br /><br />You can't and really shouldn't override the equals() and compareTo() methods. These have special meanings with regards to the lower level Hibernate stuff and even the JVM has certain expectations with respect to their implementations and access. Besides, they can be called all over the place when you least expect and wouldn't want all of these extra service invokes any time they're used.</blockquote><br /><br />Thank you David H Nebinger,<br /><br />that was the clear answer I couldn't distill from the google searches prior.Sotoku Alekido2015-07-29T13:03:34ZRE: Service Builder: Overriding toCompare generates wrong codeRamalingaiah. Dhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=568693552015-07-29T12:48:35Z2015-07-29T12:48:35ZSorry David H Nebinger,<br /><br />i am learning liferay portal<br />please give me suggestion,<br /><br />Regards<br />RamRamalingaiah. D2015-07-29T12:48:35ZRE: Service Builder: Overriding toCompare generates wrong codeDavid H Nebingerhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=568665632015-07-29T12:33:16Z2015-07-29T12:33:16Z<div class="quote-title">Ramalingaiah Dudidmetle:</div><blockquote>Hi Sototu Alekido,<br />this for only service.xml inside past code --->deploy---> service builder --->then it will come for table and src code <br /></blockquote><br /><br />Um, it wasn't useful at all because you didn't address the OP's question, you just threw out a post with some crap on it.David H Nebinger2015-07-29T12:33:16ZRE: Service Builder: Overriding toCompare generates wrong codeDavid H Nebingerhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=568665512015-07-29T12:31:31Z2015-07-29T12:31:31Z<div class="quote-title">Sototu Alekido:</div><blockquote>In the generated {Entityname}Impl.java classes I override the methods equals(Object object) and compareTo({Entityname} entity). After the regeneration, the classes {Entityname}Clp.java and {Entityname}Wrapper.java have the methods equals and compareTo each two times defined which of course throws a duplicated methode exception.<br /><br />Is there a solution for this or do I have to take the compareTo and equals methods the service builder is forcing me to use?</blockquote><br /><br />You can't and really shouldn't override the equals() and compareTo() methods. These have special meanings with regards to the lower level Hibernate stuff and even the JVM has certain expectations with respect to their implementations and access. Besides, they can be called all over the place when you least expect and wouldn't want all of these extra service invokes any time they're used.David H Nebinger2015-07-29T12:31:31ZRE: Service Builder: Overriding toCompare generates wrong codeSotoku Alekidohttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=568682732015-07-29T12:20:38Z2015-07-29T12:20:38ZThanks Ramalingaiah Dudidmetle,<br /><br />I edited the generated code after their generation, if I unterstood rightly.<br /><br />I think I will resolve this problem for me by accepting the enforcement of the service builder and rebuild the parts of the projects depending on this service.Sotoku Alekido2015-07-29T12:20:38ZRE: Service Builder: Overriding toCompare generates wrong codeRamalingaiah. Dhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=568561562015-07-29T09:44:50Z2015-07-29T09:44:50ZHi Sototu Alekido,<br />this for only service.xml inside past code --->deploy---> service builder --->then it will come for table and src code <br />this useful for you <br /><entity name="LMSBook" local-service="true" remote-service="false"> <!-- PK fields --> <br /> <br /> <column name="bookId" type="long" primary="true" id-type="increment" /> <!-- UI fields --><br /> <br /> <column name="bookTitle" type="String" /><br /> <br /> <column name="author" type="String" /> <!-- Audit fields --> <br /> <br /> <column name="createDate" type="Date" /><br /> <br /> <column name="phone" type="String" /><br /> <br /> <column name="email" type="String"/><br /> <br /> </entity>Ramalingaiah. D2015-07-29T09:44:50ZService Builder: Overriding toCompare generates wrong codeSotoku Alekidohttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=568507792015-07-29T07:47:31Z2015-07-29T07:47:31ZHello everyone,<br /><br />I hope someone can help me with this issue.<br /><br /><strong>What I have done so far:</strong><br />After defining the tables and columns in the file service.xml, the service layer is generated from it through the command <span style="font-family: Tahoma">mvn liferay:build-service</span>, which is performed successfully. In the following process, I write my own methods into the generated {Entityname}Impl.java classes and after that I let the service builder regenera