Skip to content

Commit ba3f533

Browse files
committed
HHH-18347 Fix cast type name using dialect's default size strategy
Also tests failing on MariaDB by avoiding `id` keyword as column name
1 parent cee623c commit ba3f533

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/internal/DdlTypeImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,15 @@ public String getCastTypeName(JdbcType jdbcType, JavaType<?> javaType, Long leng
114114
}
115115
else {
116116
//use the given length/precision/scale
117-
if ( precision != null && scale == null ) {
117+
final Size size = dialect.getSizeStrategy()
118+
.resolveSize( jdbcType, javaType, precision, scale, length );
119+
if ( size.getPrecision() != null && size.getScale() == null ) {
118120
//needed for cast(x as BigInteger(p))
119-
scale = javaType.getDefaultSqlScale( dialect, jdbcType );
121+
size.setScale( javaType.getDefaultSqlScale( dialect, jdbcType ) );
120122
}
121123
return castTypeNamePattern == null
122-
? getTypeName( length, precision, scale )
123-
: replace( castTypeNamePattern, length, precision, scale );
124+
? getTypeName( size.getLength(), size.getPrecision(), size.getScale() )
125+
: replace( castTypeNamePattern, size.getLength(), size.getPrecision(), size.getScale() );
124126
}
125127
}
126128

hibernate-core/src/test/resources/mappings/subselectfetch/Name.hbm.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
<hibernate-mapping>
1313

1414
<class name="org.hibernate.orm.test.mapping.fetch.subselect.Name" table="T_Name">
15-
<id name="id" column="id"/>
15+
<id name="id" column="c_id"/>
1616
<property name="name" column="c_name"/>
1717

18-
<property name="nameLength" formula="(select length(c_name) from T_Name where id = T_Name.id)"/>
18+
<property name="nameLength" formula="(select length(sub.c_name) from T_Name sub where c_id = sub.c_id)"/>
1919

2020
<bag name="values" inverse="true" lazy="false" fetch="subselect">
2121
<key column="name_id"/>

hibernate-core/src/test/resources/org/hibernate/orm/test/bidi/Auction.hbm.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
package="org.hibernate.orm.test.bidi">
1414

1515
<class name="Auction" table="TAuction">
16-
<id name="id">
16+
<id name="id" column="c_id">
1717
<generator class="native"/>
1818
</id>
1919
<property name="description"/>
@@ -25,13 +25,13 @@
2525
</bag>
2626
<one-to-one name="successfulBid"
2727
property-ref="abc">
28-
<formula>id</formula>
28+
<formula>c_id</formula>
2929
<formula>true</formula>
3030
</one-to-one>
3131
</class>
3232

3333
<class name="Bid" table="TBid">
34-
<id name="id">
34+
<id name="id" column="c_id">
3535
<generator class="native"/>
3636
</id>
3737
<property name="amount"

hibernate-core/src/test/resources/org/hibernate/orm/test/bidi/Auction2.hbm.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
package="org.hibernate.orm.test.bidi">
1414

1515
<class name="Auction" table="TAuction2">
16-
<id name="id">
16+
<id name="id" column="c_id">
1717
<generator class="native"/>
1818
</id>
1919
<property name="description"/>
@@ -27,7 +27,7 @@
2727
</class>
2828

2929
<class name="Bid" table="TBid2">
30-
<id name="id">
30+
<id name="id" column="c_id">
3131
<generator class="native"/>
3232
</id>
3333
<property name="amount" scale="19" precision="31"/>
@@ -37,7 +37,7 @@
3737
column="auctionId"
3838
cascade="persist"/>
3939
<property name="successful">
40-
<formula>exists(select a.id from TAuction2 a where a.successfulBid=id)</formula>
40+
<formula>exists(select a.c_id from TAuction2 a where a.successfulBid=c_id)</formula>
4141
</property>
4242
</class>
4343

hibernate-core/src/test/resources/org/hibernate/orm/test/bidi/Auction3.hbm.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
package="org.hibernate.orm.test.bidi">
1414

1515
<class name="SpecialAuction" table="TAuction">
16-
<id name="id">
16+
<id name="id" column="c_id">
1717
<generator class="native"/>
1818
</id>
1919
<property name="description"/>
@@ -25,13 +25,13 @@
2525
</bag>
2626
<one-to-one name="successfulBid"
2727
property-ref="abc">
28-
<formula>id</formula>
28+
<formula>c_id</formula>
2929
<formula>true</formula>
3030
</one-to-one>
3131
</class>
3232

3333
<class name="AbstractBid" table="TBid" abstract="true">
34-
<id name="id">
34+
<id name="id" column="c_id">
3535
<generator class="native"/>
3636
</id>
3737

0 commit comments

Comments
 (0)