Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping empty postgres text[] column sets field to null in 3.3.1 #1826

Closed
Tree4Free opened this issue Jun 25, 2024 · 2 comments
Closed

Mapping empty postgres text[] column sets field to null in 3.3.1 #1826

Tree4Free opened this issue Jun 25, 2024 · 2 comments
Assignees
Labels
type: regression A regression from a previous release

Comments

@Tree4Free
Copy link

As written in this comment #1737 (comment) after upgrading to spring-data-jdbc 3.3.1 when I load an entity with a text[] column (mapped as List<String>) that is empty using findById the column is set to null.

My guess is that bug was introduced by this issue #1737 but I didn't look into the changes to confirm that.


An example of my setup taken from the comment linked above:

Using a combination of Java + Kotlin:
My Entity: (Java + Lombok)

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
public class MyTable extends Entity {
    List<String> tags;
}

My database table (postgres):

create table my_table
(
    id uuid not null,
    version bigint not null,
    tags text[] not null,
    constraint pk_my_table primary key (id)
);

My test case (Kotlin)

@Repository
interface MyTableRepository: CrudRepository<MyTable, UUID>, PagingAndSortingRepository<MyTable, UUID>

@Test
fun test() {
    val instance = myTableRepository.save(MyTable(null, 0, emptyList())) // instance.tags is still an empty list
    assertNotNull(myTableRepository.findById(instance.id).get().tags) // data from db tags is null
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 25, 2024
@Tree4Free Tree4Free reopened this Jun 26, 2024
@schauder
Copy link
Contributor

I tried to reproduce the issue but failed

Please provide a Minimimal Reproducable Example, preferable as a Github repository. Make sure to include the database, either as an in memory database or if that is not possible using Testcontainers.

@schauder schauder added the status: waiting-for-feedback We need additional information before we can continue label Jun 26, 2024
@Tree4Free
Copy link
Author

Tree4Free commented Jun 26, 2024

Here is the repo:

https://github.com/Tree4Free/spring-data-jdbc-issue-1826

I used a postgres testcontainer because thats where I also discovered the issue in my code.
You can find the failing test under com.example.springjdbcnullissue.SpringJdbcNullIssueApplicationTests#testNullTextArray

(JDK used is 21)

When changing the version of the org.springframework.boot plugin in the build.gradle.kts to 3.3.0 from 3.3.1 the test case succeeds.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jun 26, 2024
schauder added a commit that referenced this issue Jul 2, 2024
schauder added a commit that referenced this issue Jul 2, 2024
@schauder schauder added this to the 3.2.8 (2023.1.8) milestone Jul 2, 2024
@schauder schauder self-assigned this Jul 2, 2024
@schauder schauder added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

3 participants