Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions hibernate-dialect-v6/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
TODO: Set actual version
## 0.9.x ##

- Fixed `lower` and `upper` functions: replaced `Unicode::ToLower`/`Unicode::ToUpper` with YQL built-in functions compatible with `Text`/`String` column types

## 1.5.3 ##

- Support `lower`, `upper` and `concat` functions
Expand Down
1 change: 1 addition & 0 deletions hibernate-dialect-v6/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<groupId>tech.ydb.dialects</groupId>
<artifactId>hibernate-ydb-dialect</artifactId>
<!-- TODO: Set actual version -->
<version>1.5.3</version>

<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio

functionRegistry.registerPattern(
"lower",
"Unicode::ToLower(?1)"
"String::AsciiToLower(?1)"
);

functionRegistry.registerPattern(
"upper",
"Unicode::ToUpper(?1)"
"String::AsciiToUpper(?1)"
);

functionRegistry.patternDescriptorBuilder("concat", "(?1||?2...)")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package tech.ydb.hibernate.string;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

@Entity
@Table(name = "string_test")
public class StringEntity {
@Id
@Column(name = "id")
public int id;

@Column(name = "name")
public String name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.junit.jupiter.api.extension.RegisterExtension;
import tech.ydb.test.junit5.YdbHelperExtension;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static tech.ydb.hibernate.TestUtils.*;

Expand All @@ -20,6 +22,7 @@ public class StringFunctionsTest {
@BeforeAll
static void beforeAll() {
SESSION_FACTORY = basedConfiguration()
.addAnnotatedClass(StringEntity.class)
.setProperty(AvailableSettings.URL, jdbcUrl(ydb))
.buildSessionFactory();
}
Expand Down Expand Up @@ -48,4 +51,25 @@ void concatFunctionTest() {
.createQuery("select concat('text')")
.getSingleResult()));
}

@Test
void lowerOnColumnWithLikeTest() {
inTransaction(session -> {
StringEntity entity = new StringEntity();
entity.id = 1;
entity.name = "test entity";
session.persist(entity);
});

inTransaction(session -> {
List<StringEntity> result = session
.createQuery(
"select e from StringEntity e where lower(e.name) like lower(concat('%', :search, '%'))",
StringEntity.class
)
.setParameter("search", "test")
.getResultList();
assertEquals(1, result.size());
});
}
}
5 changes: 5 additions & 0 deletions hibernate-dialect-v7/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
TODO: Set actual version
## 0.9.x ##

- Fixed `lower` and `upper` functions: replaced `Unicode::ToLower`/`Unicode::ToUpper` with YQL built-in functions compatible with `Text`/`String` column types

## 0.9.2 ##

- Support `concat` function
Expand Down
1 change: 1 addition & 0 deletions hibernate-dialect-v7/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<groupId>tech.ydb.dialects</groupId>
<artifactId>hibernate-ydb-dialect-v7</artifactId>
<!-- TODO: Set actual version -->
<version>0.9.2</version>

<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio

functionRegistry.registerPattern(
"lower",
"Unicode::ToLower(?1)"
"String::AsciiToLower(?1)"
);

functionRegistry.registerPattern(
"upper",
"Unicode::ToUpper(?1)"
"String::AsciiToUpper(?1)"
);

functionRegistry.patternDescriptorBuilder("concat", "(?1||?2...)")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package tech.ydb.hibernate.string;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

@Entity
@Table(name = "string_test")
public class StringEntity {
@Id
@Column(name = "id")
public int id;

@Column(name = "name")
public String name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.junit.jupiter.api.extension.RegisterExtension;
import tech.ydb.test.junit5.YdbHelperExtension;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static tech.ydb.hibernate.TestUtils.*;

Expand All @@ -20,6 +22,7 @@ public class StringFunctionsTest {
@BeforeAll
static void beforeAll() {
SESSION_FACTORY = basedConfiguration()
.addAnnotatedClass(StringEntity.class)
.setProperty(AvailableSettings.URL, jdbcUrl(ydb))
.buildSessionFactory();
}
Expand Down Expand Up @@ -48,4 +51,25 @@ void concatFunctionTest() {
.createQuery("select concat('text')")
.getSingleResult()));
}
}

@Test
void lowerOnColumnWithLikeTest() {
inTransaction(session -> {
StringEntity entity = new StringEntity();
entity.id = 1;
entity.name = "test entity";
session.persist(entity);
});

inTransaction(session -> {
List<StringEntity> result = session
.createQuery(
"select e from StringEntity e where lower(e.name) like lower(concat('%', :search, '%'))",
StringEntity.class
)
.setParameter("search", "test")
.getResultList();
assertEquals(1, result.size());
});
}
}
Loading