I am having a problem mapping an existing schema into Hibernate. The problem is, we had an class hierarchy that was mapped on different tables, so, in order to map to Hibernate we had to use union-subclass. But, the problem was that on 2 different concrete classes we had fields with the same name, mapped to rows with the same names but with different types (varchar and int) and appearently Hibernate is assigning the same column alias on query generation for another class that has an association to the base class of that class hierarchy. If I comment out the mapping for any of the field, the query is run successfully but only one of the fields get loaded, if both of the fields are mapped the faulty query is generated.
Hibernate version:
3.0.5
Mapping documents:
<hibernate-mapping package="...">
<class name="AbstractContentDetails" abstract="true">
<id name="pcrId" type="long" unsaved-value="0" column="pcr_id">
<generator class="assigned">
<param name="property">physicalContentRevision</param>
</generator>
</id>
<one-to-one name="physicalContentRevision" class="PhysicalContentRevisionDO" constrained="true"/>
<property name="fileSize" type="int" column="file_size"/>
<union-subclass name="MPEGAudioDetails" table="mpeg_audio_details">
<property name="samplingRate" type="int" column="sampling_rate"/>
<property name="numberOfChannels" type="int" column="number_of_channels"/>
<property name="version" type="int"/>
<property name="layer" type="int" column="mpeg_layer"/>
<property name="channelMode" type="string" length="200" column="channel_mode"/>
<property name="channelModeExtension" type="string" length="200" column="channel_mode_extension"/>
<property name="title" type="string" length="200"/>
<property name="artist" type="string" length="200"/>
<property name="album" type="string" length="200"/>
<property name="year" type="string" length="200" column="year_of_issue"/>
<property name="comment" type="string" length="200" column="comment_text"/>
<property name="genre" type="string" length="200"/>
</union-subclass>
<union-subclass name="AbstractImageDetails" abstract="true">
<property name="height" type="int"/>
<property name="width" type="int"/>
<property name="colorDepth" type="int" column="color_depth"/>
<union-subclass name="JPEGDetails" table="jpeg_details">
<property name="version" type="string" length="200"/>
<property name="units" type="int"/>
<property name="densityX" type="int" column="x_density"/>
<property name="densityY" type="int" column="y_density"/>
<property name="physicalWidthDPI" type="int" column="physical_width_dpi"/>
<property name="physicalHeightDPI" type="int" column="physical_height_dpi"/>
</union-subclass>
</union-subclass>
</class>
</hibernate-mapping>
/* Class that refers to previous one */
<hibernate-mapping package="...">
<class name="PhysicalContentRevisionDO" table="PHYSICAL_CONTENT_REVISION" dynamic-update="false">
<id name="id" column="ID" type="long" access="field">
<generator class="assigned"/>
</id>
<property name="name" type="string" column="NAME" access="field"/>
<... long mapping .../>
<one-to-one name="contentDetails" class="AbstractContentDetails"/>
<... long mapping .../>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Long code, basically it tries to list the PhysicalContentRevisionDO class.
Full stack trace of any exception that occurs:
<Error> <Unknown> <org.hibernate.util.JDBCExcepti
onReporter: ORA-01790: expression must have same datatype as corresponding expre
ssion
>
Name and version of the database you are using:
Oracle9i Enterprise Edition Release 9.2.0.6.0
The generated SQL (show_sql=true):
select abstractco0_.pcr_id as pcr1_0_, abstractco0_.file_size as file2_34_0_, abstractco0_.sampling_rate as sampling1_35_0_, abstractco0_.number_of_channels as number2_35_0_, abstractco0_.version as version35_0_, abstractco0_.mpeg_layer as mpeg4_35_0_, abstractco0_.channel_mode as channel5_35_0_, abstractco0_.channel_mode_extension as channel6_35_0_, abstractco0_.title as title35_0_, abstractco0_.artist as artist35_0_, abstractco0_.album as album35_0_, abstractco0_.year_of_issue as year10_35_0_, abstractco0_.comment_text as comment11_35_0_, abstractco0_.genre as genre35_0_, abstractco0_.height as height36_0_, abstractco0_.width as width36_0_, abstractco0_.color_depth as color3_36_0_, abstractco0_.number_of_images as number1_37_0_, abstractco0_.version as version37_0_, abstractco0_.version as version38_0_, abstractco0_.units as units38_0_, abstractco0_.x_density as x3_38_0_, abstractco0_.y_density as y4_38_0_, abstractco0_.physical_width_dpi as physical5_38_0_, abstractco0_.physical_height_dpi as physical6_38_0_, abstractco0_.clazz_ as clazz_0_ from ( select nullif(0,0) as x_density, nullif('x','x') as genre, nullif(0,0) as number_of_channels, version, nullif('x','x') as artist, nullif(0,0) as physical_height_dpi, nullif(0,0) as mpeg_layer, nullif('x','x') as channel_mode_extension, nullif(0,0) as y_density, nullif('x','x') as year_of_issue, file_size, nullif('x','x') as comment_text, height, color_depth, nullif(0,0) as physical_width_dpi, nullif('x','x') as album, width, nullif(0,0) as units, number_of_images, nullif(0,0) as sampling_rate, nullif('x','x') as channel_mode, pcr_id, nullif('x','x') as title, 3 as clazz_ from gif_details union all select x_density, nullif('x','x') as genre, nullif(0,0) as number_of_channels, version, nullif('x','x') as artist, physical_height_dpi, nullif(0,0) as mpeg_layer, nullif('x','x') as channel_mode_extension, y_density, nullif('x','x') as year_of_issue, file_size, nullif('x','x') as comment_text, height, color_depth, physical_width_dpi, nullif('x','x') as album, width, units, nullif(0,0) as number_of_images, nullif(0,0) as sampling_rate, nullif('x','x') as channel_mode, pcr_id, nullif('x','x') as title, 4 as clazz_ from jpeg_details union all select nullif(0,0) as x_density, genre, number_of_channels, version, artist, nullif(0,0) as physical_height_dpi, mpeg_layer, channel_mode_extension, nullif(0,0) as y_density, year_of_issue, file_size, comment_text, nullif(0,0) as height, nullif(0,0) as color_depth, nullif(0,0) as physical_width_dpi, album, nullif(0,0) as width, nullif(0,0) as units, nullif(0,0) as number_of_images, sampling_rate, channel_mode, pcr_id, title, 1 as clazz_ from mpeg_audio_details ) abstractco0_ where abstractco0_.pcr_id=?
_________________ Rafael Ribeiro
|