facebook

Another error in GeneratePOJO

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

    macinsmith
    Member

    It seems that GeneratePOJO doesn’t handle composite-element correctly or at least it doesn’t generate all the necessary POJOs. Here are the three hmb.xml mapping files.

    Album.hbm.xml

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
              "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
    
    <hibernate-mapping>
      <class name="com.oreilly.hh.Album" table="ALBUM">
        <meta attribute="class-description">
          Represents an album in the music database, an organized list of tracks.
          @author Jim Elliott (with help from Hibernate)
        </meta>
    
        <id name="id" type="int" column="ALBUM_ID">
          <meta attribute="scope-set">protected</meta>
          <generator class="native"/>
        </id>
    
        <property name="title" type="string">
          <meta attribute="use-in-tostring">true</meta>
          <column name="TITLE" not-null="true" index="ALBUM_TITLE"/>
        </property>
    
        <property name="numDiscs" type="integer" not-null="true"/>
    
        <set name="artists" table="ALBUM_ARTISTS">
          <key column="ALBUM_ID"/>
          <many-to-many class="com.oreilly.hh.Artist" column="ARTIST_ID"/>
        </set>
    
        <set name="comments" table="ALBUM_COMMENTS">
          <key column="ALBUM_ID"/>
          <element column="COMMENT" type="string"/>
        </set>
    
        <list name="tracks" table="ALBUM_TRACKS" cascade="all">
          <meta attribute="use-in-tostring">true</meta>
          <key column="ALBUM_ID"/>
          <index column="POS"/>
          <composite-element class="com.oreilly.hh.AlbumTrack">
            <many-to-one name="track" class="com.oreilly.hh.Track" cascade="all">
              <meta attribute="use-in-tostring">true</meta>
              <column name="TRACK_ID"/>
            </many-to-one>
            <property name="disc" type="integer" not-null="true"/>
            <property name="positionOnDisc" type="integer" not-null="true"/>
          </composite-element>
        </list>
    
        <property name="added" type="date">
          <meta attribute="field-description">When the album was added</meta>
        </property>
    
      </class>
    </hibernate-mapping>
    

    Artist.hbm.xml

    <?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>
    
      <class name="com.oreilly.hh.Artist" table="ARTIST">
        <meta attribute="class-description">
          Represents an artist who is associated with a track or album.
          @author Jim Elliott (with help from Hibernate)
        </meta>
    
        <id name="id" type="int" column="ARTIST_ID">
          <meta attribute="scope-set">protected</meta>
          <generator class="native"/>
        </id>
    
        <property name="name" type="string">
          <meta attribute="use-in-tostring">true</meta>
          <column name="NAME" not-null="true" unique="true" index="ARTIST_NAME"/>
        </property>
    
        <set name="tracks" table="TRACK_ARTISTS" inverse="true">
          <meta attribute="field-description">Tracks by this artist</meta>
          <key column="ARTIST_ID"/>
          <many-to-many class="com.oreilly.hh.Track" column="TRACK_ID"/>
        </set>
    
        <many-to-one name="actualArtist" class="com.oreilly.hh.Artist">
          <meta attribute="use-in-tostring">true</meta>
        </many-to-one>
    
      </class>
    
      <query name="com.oreilly.hh.artistByName">
        <![CDATA[
            from com.oreilly.hh.Artist as artist
            where upper(artist.name) = upper(:name)
          ]]>
      </query>
    
    </hibernate-mapping>
    

    Track.hbm.xml

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
              "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
    
    <hibernate-mapping>
    
      <class name="com.oreilly.hh.Track" table="TRACK">
        <meta attribute="class-description">
          Represents a single playable track in the music database.
          @author Jim Elliott (with help from Hibernate)
        </meta>
    
        <id name="id" type="int" column="TRACK_ID">
          <meta attribute="scope-set">protected</meta>
          <generator class="native"/>
        </id>
    
        <property name="title" type="string">
          <meta attribute="use-in-tostring">true</meta>
          <column name="TITLE" not-null="true" index="TRACK_TITLE"/>
        </property>
    
        <property name="filePath" type="string" not-null="true"/>
    
        <property name="playTime" type="time">
          <meta attribute="field-description">Playing time</meta>
        </property>
    
        <set name="artists" table="TRACK_ARTISTS">
          <key column="TRACK_ID"/>
          <many-to-many class="com.oreilly.hh.Artist" column="ARTIST_ID"/>
        </set>
    
        <set name="comments" table="TRACK_COMMENTS">
          <key column="TRACK_ID"/>
          <element column="COMMENT" type="string"/>
        </set>
    
        <property name="added" type="date">
          <meta attribute="field-description">When the track was added</meta>
        </property>
    
        <property name="volume" type="com.oreilly.hh.StereoVolumeType">
          <meta attribute="field-description">How loud to play the track</meta>
          <meta attribute="use-in-tostring">true</meta>
          <column name="VOL_LEFT"/>
          <column name="VOL_RIGHT"/>
        </property>
    
        <property name="sourceMedia" type="com.oreilly.hh.SourceMediaType">
          <meta attribute="field-description">Media on which track was obtained</meta>
          <meta attribute="use-in-tostring">true</meta>
        </property>
    
      </class>
    
      <query name="com.oreilly.hh.tracksNoLongerThan">
        <![CDATA[
            from com.oreilly.hh.Track as track
            where track.playTime <= :length
          ]]>
      </query>
    
    </hibernate-mapping>
    

    This should generate 4 files Album.java, AlbumTrack.java, Artist.java and Track.java but it fails to generate AlbumTrack.java. This code is taken from Oreilly’s book Hibernate:A Developer’s Notebook by Elliott.

    #250117 Reply

    Riyad Kalla
    Member

    Mac let’s track the improvements of the POJOs in the other thread you started where snpe replied to you.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Another error in GeneratePOJO

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