HHH-18347 Fix cast type name using dialect's default size strategy

Also tests failing on MariaDB by avoiding `id` keyword as column name
This commit is contained in:
Marco Belladelli 2024-07-08 11:07:23 +02:00
parent cbe2f6ff89
commit 04ab85f155
5 changed files with 17 additions and 15 deletions

View File

@ -114,13 +114,15 @@ public class DdlTypeImpl implements DdlType {
} }
else { else {
//use the given length/precision/scale //use the given length/precision/scale
if ( precision != null && scale == null ) { final Size size = dialect.getSizeStrategy()
.resolveSize( jdbcType, javaType, precision, scale, length );
if ( size.getPrecision() != null && size.getScale() == null ) {
//needed for cast(x as BigInteger(p)) //needed for cast(x as BigInteger(p))
scale = javaType.getDefaultSqlScale( dialect, jdbcType ); size.setScale( javaType.getDefaultSqlScale( dialect, jdbcType ) );
} }
return castTypeNamePattern == null return castTypeNamePattern == null
? getTypeName( length, precision, scale ) ? getTypeName( size.getLength(), size.getPrecision(), size.getScale() )
: replace( castTypeNamePattern, length, precision, scale ); : replace( castTypeNamePattern, size.getLength(), size.getPrecision(), size.getScale() );
} }
} }

View File

@ -12,10 +12,10 @@
<hibernate-mapping> <hibernate-mapping>
<class name="org.hibernate.orm.test.mapping.fetch.subselect.Name" table="T_Name"> <class name="org.hibernate.orm.test.mapping.fetch.subselect.Name" table="T_Name">
<id name="id" column="id"/> <id name="id" column="c_id"/>
<property name="name" column="c_name"/> <property name="name" column="c_name"/>
<property name="nameLength" formula="(select length(c_name) from T_Name where id = T_Name.id)"/> <property name="nameLength" formula="(select length(sub.c_name) from T_Name sub where c_id = sub.c_id)"/>
<bag name="values" inverse="true" lazy="false" fetch="subselect"> <bag name="values" inverse="true" lazy="false" fetch="subselect">
<key column="name_id"/> <key column="name_id"/>

View File

@ -13,7 +13,7 @@
package="org.hibernate.orm.test.bidi"> package="org.hibernate.orm.test.bidi">
<class name="Auction" table="TAuction"> <class name="Auction" table="TAuction">
<id name="id"> <id name="id" column="c_id">
<generator class="native"/> <generator class="native"/>
</id> </id>
<property name="description"/> <property name="description"/>
@ -25,13 +25,13 @@
</bag> </bag>
<one-to-one name="successfulBid" <one-to-one name="successfulBid"
property-ref="abc"> property-ref="abc">
<formula>id</formula> <formula>c_id</formula>
<formula>true</formula> <formula>true</formula>
</one-to-one> </one-to-one>
</class> </class>
<class name="Bid" table="TBid"> <class name="Bid" table="TBid">
<id name="id"> <id name="id" column="c_id">
<generator class="native"/> <generator class="native"/>
</id> </id>
<property name="amount" <property name="amount"

View File

@ -13,7 +13,7 @@
package="org.hibernate.orm.test.bidi"> package="org.hibernate.orm.test.bidi">
<class name="Auction" table="TAuction2"> <class name="Auction" table="TAuction2">
<id name="id"> <id name="id" column="c_id">
<generator class="native"/> <generator class="native"/>
</id> </id>
<property name="description"/> <property name="description"/>
@ -27,7 +27,7 @@
</class> </class>
<class name="Bid" table="TBid2"> <class name="Bid" table="TBid2">
<id name="id"> <id name="id" column="c_id">
<generator class="native"/> <generator class="native"/>
</id> </id>
<property name="amount" scale="19" precision="31"/> <property name="amount" scale="19" precision="31"/>
@ -37,7 +37,7 @@
column="auctionId" column="auctionId"
cascade="persist"/> cascade="persist"/>
<property name="successful"> <property name="successful">
<formula>exists(select a.id from TAuction2 a where a.successfulBid=id)</formula> <formula>exists(select a.c_id from TAuction2 a where a.successfulBid=c_id)</formula>
</property> </property>
</class> </class>

View File

@ -13,7 +13,7 @@
package="org.hibernate.orm.test.bidi"> package="org.hibernate.orm.test.bidi">
<class name="SpecialAuction" table="TAuction"> <class name="SpecialAuction" table="TAuction">
<id name="id"> <id name="id" column="c_id">
<generator class="native"/> <generator class="native"/>
</id> </id>
<property name="description"/> <property name="description"/>
@ -25,13 +25,13 @@
</bag> </bag>
<one-to-one name="successfulBid" <one-to-one name="successfulBid"
property-ref="abc"> property-ref="abc">
<formula>id</formula> <formula>c_id</formula>
<formula>true</formula> <formula>true</formula>
</one-to-one> </one-to-one>
</class> </class>
<class name="AbstractBid" table="TBid" abstract="true"> <class name="AbstractBid" table="TBid" abstract="true">
<id name="id"> <id name="id" column="c_id">
<generator class="native"/> <generator class="native"/>
</id> </id>