question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ListArrayType should match the initial type when populating the List with the array from the DB

See original GitHub issue

When having a entity like:

@Entity
@TypeDefs({
        @TypeDef(name = "list-array", typeClass = ListArrayType.class)
})
public class Circuit {

    @Column(name = "previous_names")
    @Type(type = "list-array")
    private List<String> previousNames = new ArrayList<>();

    ..

Could the ListArrayType add the names to the initiated list instead of replacing the list?

I’m wondering as when the array is null in the database the previousNames list will be null in the fetched entity. I’m having 2 feelings here as it makes sense if it’s null in the database.

But I expected differently.

Similar as

    @OneToMany(mappedBy = "project")
    private List<Task> tasks = new ArrayList<>();

will also give an empty list, even if no tasks would be found in the databse.

Maybe

    @Type(type = "list-array")
    private List<String> previousNames = new ArrayList<>();

could return an empty list.

and

    @Type(type = "list-array")
    private List<String> previousNames;

could return null.

What do you think?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
vladmihalceacommented, Jan 15, 2020

You’re welcome. I think the current behavior follows the “principle_of_least_astonishment”, so it’s better to leave it as-is.

0reactions
marceloverdijkcommented, Jan 15, 2020

OK, I wasn’t aware of the @Basic property rules, but it makes sense. I indeed added a getter like that already. Thx again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - The type of the expression must be an array type but it ...
An ArrayList is not an array . The syntax to get the element at index i is different: list.get(i) vs arr[i] . Read...
Read more >
Arrays - Rosetta Code
Creating an array is as simple as declaring its base address. Note that all bounds checking must be done by the programmer and...
Read more >
Documentation: 15: 8.15. Arrays - PostgreSQL
To illustrate the use of array types, we create this table: ... Multidimensional arrays must have matching extents for each dimension.
Read more >
How To Manage State in React with Redux - DigitalOcean
That means your actions and reducers will be defined by the type of feature they will impact. Create a directory called store :...
Read more >
How to map a PostgreSQL ARRAY to a Java List with JPA and ...
Even if Hibernate ORM does not support these column type mappings by default, you can still use all these database column types as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found