facebook

Abstract base classes for components

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #255633 Reply

    Woyzeck
    Member

    “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 ?

    #255676 Reply

    Riyad Kalla
    Member

    I’ve passed this along to our Hibernate guru to answer.

    #255698 Reply

    Haris Peco
    Member

    Woyzeck,

    Please can you send example mapping

    Best regards

    #255708 Reply

    Woyzeck
    Member

    An 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>
    #255975 Reply

    Woyzeck
    Member

    Any additional comments on this subject ?

    #256022 Reply

    Haris Peco
    Member

    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 point

    Thanks
    Peco

    #256040 Reply

    Woyzeck
    Member

    @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 point

    Thanks
    Peco

    Every 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”.

    #256041 Reply

    Haris Peco
    Member

    It’s clear.
    I will file report about this and we will probably implement in future releases

    Thanks

    #256042 Reply

    Woyzeck
    Member

    Thank you for your fast and helpful reply. It’s good to see quality in support.

Viewing 9 posts - 1 through 9 (of 9 total)
Reply To: Abstract base classes for components

You must be logged in to post in the forum log in