Skip to content

Commit 43e0914

Browse files
VladoKurucbeikov
authored andcommitted
Fixed Informix physical naming strategy compatibility
1 parent 3a30ca2 commit 43e0914

File tree

25 files changed

+225
-182
lines changed

25 files changed

+225
-182
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/query/AllTables.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
public class AllTables {
2727

2828
@Id
29-
@Column(name = "TABLE_NAME", nullable = false)
29+
@Column(name = "table_name", nullable = false)
3030
private String tableName;
3131

3232
@Formula(value = "(SYSDATE())")
33+
@Column(name = "days_old")
3334
private String daysOld;
3435

3536
public String getTableName() {

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/query/QueryAndSQLTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ public void testNativeQueryWithFormulaAttribute(SessionFactoryScope scope) {
9898
.currentDate();
9999

100100
String sql = String.format(
101-
"select t.TABLE_NAME as {t.tableName}, %s as {t.daysOld} from ALL_TABLES t where t.TABLE_NAME = 'AUDIT_ACTIONS' ",
101+
"select t.table_name as {t.tableName}, %s as {t.daysOld} from ALL_TABLES t where t.table_name = 'AUDIT_ACTIONS' ",
102102
dateFunctionRendered
103103
);
104104
String sql2 = String.format(
105-
"select TABLE_NAME as t_name, %s as t_time from ALL_TABLES where TABLE_NAME = 'AUDIT_ACTIONS' ",
105+
"select table_name as t_name, %s as t_time from ALL_TABLES where table_name = 'AUDIT_ACTIONS' ",
106106
dateFunctionRendered
107107
);
108108

@@ -128,8 +128,8 @@ public void testNativeQueryWithFormulaAttribute(SessionFactoryScope scope) {
128128
public void testNativeQueryWithFormulaAttributeWithoutAlias(SessionFactoryScope scope) {
129129
scope.inTransaction(
130130
session -> {
131-
String sql = "select TABLE_NAME , " + scope.getSessionFactory().getJdbcServices().getDialect()
132-
.currentDate() + " as daysOld from ALL_TABLES where TABLE_NAME = 'AUDIT_ACTIONS' ";
131+
String sql = "select table_name , " + scope.getSessionFactory().getJdbcServices().getDialect()
132+
.currentDate() + " as days_old from ALL_TABLES where table_name = 'AUDIT_ACTIONS' ";
133133
session.createNativeQuery( sql ).addEntity( "t", AllTables.class ).list();
134134
}
135135
);

hibernate-core/src/test/java/org/hibernate/orm/test/hql/joinedSubclass/JoinedSubclassNativeQueryTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.junit.jupiter.api.Test;
2121

2222
import jakarta.persistence.Basic;
23+
import jakarta.persistence.Column;
2324
import jakarta.persistence.Entity;
2425
import jakarta.persistence.GeneratedValue;
2526
import jakarta.persistence.Id;
@@ -69,7 +70,7 @@ public void testJoinedInheritanceNativeQuery(SessionFactoryScope scope) {
6970
// PostgreSQLDialect#getSelectClauseNullString produces e.g. `null::text` which we interpret as parameter,
7071
// so workaround this problem by configuring to ignore JDBC parameters
7172
session.setProperty( AvailableSettings.NATIVE_IGNORE_JDBC_PARAMETERS, true );
72-
Person p = session.createNativeQuery( "select p.*, " + nullColumnString + " as companyName, 0 as clazz_ from Person p", Person.class ).getSingleResult();
73+
Person p = session.createNativeQuery( "select p.*, " + nullColumnString + " as company_name, 0 as clazz_ from Person p", Person.class ).getSingleResult();
7374
Assertions.assertNotNull( p );
7475
Assertions.assertEquals( p.getFirstName(), "Jan" );
7576
}
@@ -84,6 +85,7 @@ public static class Person {
8485
private Long id;
8586

8687
@Basic(optional = false)
88+
@Column(name = "first_name")
8789
private String firstName;
8890

8991
public String getFirstName() {
@@ -98,6 +100,7 @@ public void setFirstName(String firstName) {
98100
@Entity(name = "Employee")
99101
public static class Employee extends Person {
100102
@Basic(optional = false)
103+
@Column(name = "company_name")
101104
private String companyName;
102105

103106
public String getCompanyName() {

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/Item.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public void setName(String name) {
107107
this.name = name;
108108
}
109109

110+
@Column(name = "int_val")
110111
public Integer getIntVal() {
111112
return intVal;
112113
}

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/Wallet.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
package org.hibernate.orm.test.jpa;
1010
import java.io.Serializable;
1111
import java.util.Date;
12+
13+
import jakarta.persistence.Column;
1214
import jakarta.persistence.Entity;
1315
import jakarta.persistence.Id;
1416

@@ -47,6 +49,7 @@ public void setBrand(String brand) {
4749
this.brand = brand;
4850
}
4951

52+
@Column(name = "market_entrance")
5053
public Date getMarketEntrance() {
5154
return marketEntrance;
5255
}

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/QueryTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -387,16 +387,16 @@ public void testNativeQueryNullPositionalParameter() throws Exception {
387387
em.persist( item );
388388
// native queries don't seem to flush by default ?!?
389389
em.flush();
390-
Query q = em.createNativeQuery( "select * from Item i where i.intVal=?" );
390+
Query q = em.createNativeQuery( "select * from Item i where i.int_val=?" );
391391
q.setParameter( 1, null );
392392
List results = q.getResultList();
393393
// null != null
394394
assertEquals( 0, results.size() );
395-
q = em.createNativeQuery( "select * from Item i where i.intVal is null and ? is null" );
395+
q = em.createNativeQuery( "select * from Item i where i.int_val is null and ? is null" );
396396
q.setParameter( 1, null );
397397
results = q.getResultList();
398398
assertEquals( 1, results.size() );
399-
q = em.createNativeQuery( "select * from Item i where i.intVal is null or i.intVal = ?" );
399+
q = em.createNativeQuery( "select * from Item i where i.int_val is null or i.int_val = ?" );
400400
q.setParameter(1, null );
401401
results = q.getResultList();
402402
assertEquals( 1, results.size() );
@@ -422,7 +422,7 @@ public void testNativeQueryNullPositionalParameterParameter() throws Exception {
422422
em.persist( item );
423423
// native queries don't seem to flush by default ?!?
424424
em.flush();
425-
Query q = em.createNativeQuery( "select * from Item i where i.intVal=?" );
425+
Query q = em.createNativeQuery( "select * from Item i where i.int_val=?" );
426426
Parameter p = new Parameter() {
427427
@Override
428428
public String getName() {
@@ -444,11 +444,11 @@ public Class getParameterType() {
444444
List results = q.getResultList();
445445
// null != null
446446
assertEquals( 0, results.size() );
447-
q = em.createNativeQuery( "select * from Item i where i.intVal is null and ? is null" );
447+
q = em.createNativeQuery( "select * from Item i where i.int_val is null and ? is null" );
448448
q.setParameter( p, null );
449449
results = q.getResultList();
450450
assertEquals( 1, results.size() );
451-
q = em.createNativeQuery( "select * from Item i where i.intVal is null or i.intVal = ?" );
451+
q = em.createNativeQuery( "select * from Item i where i.int_val is null or i.int_val = ?" );
452452
q.setParameter( p, null );
453453
results = q.getResultList();
454454
assertEquals( 1, results.size() );
@@ -473,16 +473,16 @@ public void testNativeQueryNullNamedParameter() throws Exception {
473473
em.persist( item );
474474
// native queries don't seem to flush by default ?!?
475475
em.flush();
476-
Query q = em.createNativeQuery( "select * from Item i where i.intVal=:iVal" );
476+
Query q = em.createNativeQuery( "select * from Item i where i.int_val=:iVal" );
477477
q.setParameter( "iVal", null );
478478
List results = q.getResultList();
479479
// null != null
480480
assertEquals( 0, results.size() );
481-
q = em.createNativeQuery( "select * from Item i where (i.intVal is null) and (:iVal is null)" );
481+
q = em.createNativeQuery( "select * from Item i where (i.int_val is null) and (:iVal is null)" );
482482
q.setParameter( "iVal", null );
483483
results = q.getResultList();
484484
assertEquals( 1, results.size() );
485-
q = em.createNativeQuery( "select * from Item i where i.intVal is null or i.intVal = :iVal" );
485+
q = em.createNativeQuery( "select * from Item i where i.int_val is null or i.int_val = :iVal" );
486486
q.setParameter( "iVal", null );
487487
results = q.getResultList();
488488
assertEquals( 1, results.size() );
@@ -508,7 +508,7 @@ public void testNativeQueryNullNamedParameterParameter() throws Exception {
508508
em.persist( item );
509509
// native queries don't seem to flush by default ?!?
510510
em.flush();
511-
Query q = em.createNativeQuery( "select * from Item i where i.intVal=:iVal" );
511+
Query q = em.createNativeQuery( "select * from Item i where i.int_val=:iVal" );
512512
Parameter p = new Parameter() {
513513
@Override
514514
public String getName() {
@@ -529,11 +529,11 @@ public Class getParameterType() {
529529
Parameter pGotten = q.getParameter( p.getName() );
530530
List results = q.getResultList();
531531
assertEquals( 0, results.size() );
532-
q = em.createNativeQuery( "select * from Item i where (i.intVal is null) and (:iVal is null)" );
532+
q = em.createNativeQuery( "select * from Item i where (i.int_val is null) and (:iVal is null)" );
533533
q.setParameter( p, null );
534534
results = q.getResultList();
535535
assertEquals( 1, results.size() );
536-
q = em.createNativeQuery( "select * from Item i where i.intVal is null or i.intVal = :iVal" );
536+
q = em.createNativeQuery( "select * from Item i where i.int_val is null or i.int_val = :iVal" );
537537
q.setParameter( p, null );
538538
results = q.getResultList();
539539
assertEquals( 1, results.size() );

hibernate-core/src/test/java/org/hibernate/orm/test/loaders/SqlSelectTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ void test(SessionFactoryScope scope) {
4747

4848
@Entity
4949
@Table(name = "With_Sql_Select")
50-
@SQLSelect(sql = "select * from With_Sql_Select where Sql_Select_id = ?",
50+
@SQLSelect(sql = "select * from With_Sql_Select where sql_select_id = ?",
5151
querySpaces = "With_Sql_Select")
5252
static class WithSqlSelect {
5353
@Id @GeneratedValue
54-
@Column(name = "Sql_Select_id")
54+
@Column(name = "sql_select_id")
5555
Long id;
5656
String name;
5757
@ElementCollection
5858
@CollectionTable(name = "With_Uuids",
59-
joinColumns = @JoinColumn(name = "Sql_Select_id", referencedColumnName = "Sql_Select_id"))
60-
@SQLSelect(sql = "select Random_Uuids as uuid from With_Uuids where Sql_Select_id = ?",
59+
joinColumns = @JoinColumn(name = "sql_select_id", referencedColumnName = "sql_select_id"))
60+
@SQLSelect(sql = "select Random_Uuids as uuid from With_Uuids where sql_select_id = ?",
6161
resultSetMapping = @SqlResultSetMapping(name = "",
6262
columns = @ColumnResult(name = "uuid", type = UUID.class)),
6363
querySpaces = "With_Uuids")

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/formula/FormulaNativeQueryTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import java.util.Collections;
1010
import java.util.List;
11+
12+
import jakarta.persistence.Column;
1113
import jakarta.persistence.Entity;
1214
import jakarta.persistence.GeneratedValue;
1315
import jakarta.persistence.Id;
@@ -76,7 +78,7 @@ public void testNativeQueryWithAllFields(SessionFactoryScope scope) {
7678
scope.inTransaction(
7779
session -> {
7880
Query<Foo> query = session.createNativeQuery(
79-
"SELECT ft.*, abs(locationEnd - locationStart) as distance FROM foo_table ft",
81+
"SELECT ft.*, abs(location_end - location_start) as distance FROM foo_table ft",
8082
Foo.class
8183
);
8284
List<Foo> list = query.getResultList();
@@ -90,11 +92,11 @@ public void testNativeQueryWithAliasProperties(SessionFactoryScope scope) {
9092
scope.inTransaction(
9193
session -> {
9294
NativeQuery query = session.createNativeQuery(
93-
"SELECT ft.*, abs(ft.locationEnd - locationStart) as d FROM foo_table ft" );
95+
"SELECT ft.*, abs(ft.location_end - location_start) as d FROM foo_table ft" );
9496
query.addRoot( "ft", Foo.class )
9597
.addProperty( "id", "id" )
96-
.addProperty( "locationStart", "locationStart" )
97-
.addProperty( "locationEnd", "locationEnd" )
98+
.addProperty( "locationStart", "location_start" )
99+
.addProperty( "locationEnd", "location_end" )
98100
.addProperty( "distance", "d" );
99101
List<Foo> list = query.getResultList();
100102
assertThat( list, hasSize( 3 ) );
@@ -107,7 +109,7 @@ public void testNativeQueryWithAliasSyntax(SessionFactoryScope scope) {
107109
scope.inTransaction(
108110
session -> {
109111
NativeQuery query = session.createNativeQuery(
110-
"SELECT ft.id as {ft.id}, ft.locationStart as {ft.locationStart}, ft.locationEnd as {ft.locationEnd}, abs(ft.locationEnd - locationStart) as {ft.distance} FROM foo_table ft" )
112+
"SELECT ft.id as {ft.id}, ft.location_start as {ft.locationStart}, ft.location_end as {ft.locationEnd}, abs(ft.location_end - location_start) as {ft.distance} FROM foo_table ft" )
111113
.addEntity( "ft", Foo.class );
112114
query.setProperties( Collections.singletonMap( "distance", "distance" ) );
113115
List<Foo> list = query.getResultList();
@@ -153,21 +155,23 @@ private void setId(int id) {
153155
this.id = id;
154156
}
155157

158+
@Column(name = "location_start")
156159
public int getLocationStart() {
157160
return locationStart;
158161
}
159162
public void setLocationStart(int locationStart) {
160163
this.locationStart = locationStart;
161164
}
162165

166+
@Column(name = "location_end")
163167
public int getLocationEnd() {
164168
return locationEnd;
165169
}
166170
public void setLocationEnd(int locationEnd) {
167171
this.locationEnd = locationEnd;
168172
}
169173

170-
@Formula("abs(locationEnd - locationStart)")
174+
@Formula("abs(location_end - location_start)")
171175
public int getDistance() {
172176
return distance;
173177
}

hibernate-core/src/test/java/org/hibernate/orm/test/query/NativeQueryWithDuplicateColumnTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,18 @@ public void testNativeQuery(SessionFactoryScope scope) {
121121
public static class Book {
122122
@Id
123123
@GeneratedValue
124-
@Column(name = "BOOK_ID")
124+
@Column(name = "book_id")
125125
private Long id;
126126

127127
@ManyToOne(targetEntity = Publisher.class, fetch = FetchType.LAZY)
128-
@JoinColumn(name = "PUBLISHER_FK")
128+
@JoinColumn(name = "publisher_fk")
129129
private Publisher publisher;
130130

131-
@Column(name = "PUBLISHER_FK", nullable = false, insertable = false, updatable = false)
131+
@Column(name = "publisher_fk", nullable = false, insertable = false, updatable = false)
132132
@Access(AccessType.FIELD)
133133
private Long publisherFk;
134134

135-
@Column(name = "TITLE")
135+
@Column(name = "title")
136136
private String title;
137137

138138
public Book() {

hibernate-core/src/test/java/org/hibernate/orm/test/query/sql/NativeQueryResultBuilderTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class NativeQueryResultBuilderTests {
6060
public void fullyImplicitTest(SessionFactoryScope scope) {
6161
scope.inTransaction(
6262
session -> {
63-
final String sql = "select theString, theInteger, id from EntityOfBasics";
63+
final String sql = "select the_string, the_integer, id from EntityOfBasics";
6464
final NativeQueryImplementor<?> query = session.createNativeQuery( sql );
6565

6666
final List<?> results = query.list();
@@ -91,7 +91,7 @@ public void fullyImplicitTest2(SessionFactoryScope scope) {
9191
.isNotInstanceOf( SQLServerDialect.class )
9292
.isNotInstanceOf( SybaseDialect.class )
9393
.isNotInstanceOf( OracleDialect.class );
94-
final String sql = "select count(theString) from EntityOfBasics";
94+
final String sql = "select count(the_string) from EntityOfBasics";
9595
final NativeQueryImplementor<?> query = session.createNativeQuery( sql );
9696

9797
final List<?> results = query.list();
@@ -109,12 +109,12 @@ public void fullyImplicitTest2(SessionFactoryScope scope) {
109109
public void explicitOrderTest(SessionFactoryScope scope) {
110110
scope.inTransaction(
111111
session -> {
112-
final String sql = "select theString, theInteger, id from EntityOfBasics";
112+
final String sql = "select the_string, the_integer, id from EntityOfBasics";
113113
final NativeQueryImplementor<?> query = session.createNativeQuery( sql );
114114
// notice the reverse order from the select clause
115115
query.addScalar( "id" );
116-
query.addScalar( "theInteger" );
117-
query.addScalar( "theString" );
116+
query.addScalar( "the_integer" );
117+
query.addScalar( "the_string" );
118118

119119
final List<?> results = query.list();
120120
assertThat( results.size(), is( 1 ) );

0 commit comments

Comments
 (0)