- This topic has 8 replies, 3 voices, and was last updated 18 years, 2 months ago by Woyzeck.
-
AuthorPosts
-
WoyzeckMember“Generate POJOs” creates abstract base classes for Hibernate-mapped (first class) objects, which is nice for i.e. implementing equals() and hashCode() in the actual classes.
It although creates POJOs for those objects that are mapped as components (aka ‘second class objects’), but unfortunately no abstract base classes for them. So we loose our equals() and hashCode()-implementations every time we recreate the POJOs…
Is there a way to solve this issue ?
Riyad KallaMemberI’ve passed this along to our Hibernate guru to answer.
Haris PecoMemberWoyzeck,
Please can you send example mapping
Best regards
WoyzeckMemberAn illustrative example would be the following mapping.
“Generate POJOs” will generate…
AbstractFlight
AbstractObservation
Flight
Observation
IATAFlightNumber…but no AbstractIATAFlightNumber and thus there’s no possibility to implement something like equals() and hashCode() on IATAFlightNumber, as it will be overwritten all the time.
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.quote.test.model"> <!-- * * Flight * --> <class name="Flight" abstract="true"> <id name="oid" type="java.lang.Long"> <generator class="seqhilo"> <param name="sequence">hibernate_sequence</param> <param name="max_lo">100</param> </generator> </id> <component name="iataFlightNumber" class="IATAFlightNumber"> <property name="airlineCode" column="iataFIdAirlineCode" type="java.lang.String" length="3" /> <property name="flightNumber" column="iataFIdFlightNumber" type="java.lang.String" length="8" /> <property name="suffix" column="iataFIdSuffix" type="java.lang.String" length="1" /> </component> <property name="flightNumber" type="java.lang.String" length="12" /> <property name="callsign" type="java.lang.String" length="12" /> <property name="scheduledDateTime" type="java.util.Date" not-null="true" /> <list name="observations" cascade="all-delete-orphan"> <key column="FK_OBSERVATIONS_FLIGHT" /> <index column="ORIGINDATETIME" /> <one-to-many class="Observation" /> </list> </class> <!-- * * Observation * --> <class name="Observation"> <id name="oid" type="java.lang.Long"> <generator class="seqhilo"> <param name="sequence">hibernate_sequence</param> <param name="max_lo">100</param> </generator> </id> <property name="originDateTime" type="java.util.Date" not-null="true" /> <property name="receivedDateTime" type="java.util.Date" not-null="true" /> </class> </hibernate-mapping>
WoyzeckMemberAny additional comments on this subject ?
Haris PecoMemberWoyzeck,
I’m sorry for late answer.MyEclipse can’t generate abstract classes for components, for now
I don’t sure for what you need hashCode/equals for this components (except component is part of hasCode/equals Flight class and for this you can change implementation in Flight) – sorry if I don’t understand your pointThanks
Peco
WoyzeckMember@support-snpe wrote:
Woyzeck,
I’m sorry for late answer.MyEclipse can’t generate abstract classes for components, for now
I don’t sure for what you need hashCode/equals for this components (except component is part of hasCode/equals Flight class and for this you can change implementation in Flight) – sorry if I don’t understand your pointThanks
PecoEvery object that is mapped for Hibernate should implement equals() and hashCode(). Of course it would be possible to delegate these responsibilities to the surrounding object, but that breaks oo and is considered bad design.
And yes, these components are part of the equals/hashCode method of the surrounding object (in fact they are a very important domain specific key), used for sorting, lookup in maps etc.We reuse these components in several mapped objects, i.e. the IATAFlightNumber component class is not only used for the flight, but although for the flightplan etc.
Currently we have to refetch these classes from cvs upon “generate pojos”.
Haris PecoMemberIt’s clear.
I will file report about this and we will probably implement in future releasesThanks
WoyzeckMemberThank you for your fast and helpful reply. It’s good to see quality in support.
-
AuthorPosts