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.

View Model Duplicates

See original GitHub issue

Hi,

I’m struggling with fetching data from the database. When querying for a specific RFA view, I get a duplicate for each “history” entity. So with three entries in “history”, I get the same RFA three times. I found out that Hibernate has a ResultTransformer for this problem, but this isn’t useable for blazebit when I’m correct. Furthermore, I didn’t find anything helpful in the issue section. Am I missing something?

I got the following two entities:

@Entity
@Table(name = "requests")
public class RFA {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    protected long id;

    @OneToMany(mappedBy = "rfa")
    private Set<StatusEntry> history = new HashSet<>();
}
@Entity
@Table(name = "status_history")
public class StatusEntry {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    protected long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "rfa_id")
    private RFA rfa;

}

Views:

@EntityView(RFA.class)
public interface RFAView {

    @IdMapping("id")
    Long getId();

    Set<StatusEntryView> getHistory();
}
@EntityView(StatusEntry.class)
public interface StatusEntryView {

    @IdMapping("id")
    Long getId();

}

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
j0nm1commented, Dec 15, 2019

Ok, now it’s working fine. Thank you!

0reactions
beikovcommented, Dec 13, 2019

So what you can do is either this

        CriteriaBuilder cb = cbf.create(em, RFA.class);
        int pageIndex = 1;
        int pageSize = 10;
        int firstResult = (pageIndex - 1) * pageSize;

        EntityViewSetting<RFAView, PaginatedCriteriaBuilder<RFAView>> setting = EntityViewSetting.create(RFAView.class, firstResult, pageSize);
        setting.addAttributeSorter("createDate", Sorters.descending());
        setting.addAttributeSorter("id", Sorters.descending());
        PagedList<RFAView> l = evm
                .applySetting(setting, cb)
                .getResultList();

or this

        CriteriaBuilder cb = cbf.create(em, RFA.class);
        int pageIndex = 1;
        int pageSize = 10;
        int firstResult = (pageIndex - 1) * pageSize;

        EntityViewSetting<RFAView, PaginatedCriteriaBuilder<RFAView>> setting = EntityViewSetting.create(RFAView.class, firstResult, pageSize);
        cb.orderByDesc("createDate");
        cb.orderByDesc("id");
        PagedList<RFAView> l = evm
                .applySetting(setting, cb)
                .getResultList();
Read more comments on GitHub >

github_iconTop Results From Across the Web

MVVM duplicating Model properties in ViewModel
It seems that there is a guidance that a model should not expose its entities to View, and that all required properties should...
Read more >
Duplicating Domain Model in View Model or not
A separate View Model hierarchy duplicates all of the fields in the XML model while adding error checking and everything else needed (such ......
Read more >
Duplicate class androidx.lifecycle.ViewModelLazy found in ...
ViewModelLazy found in modules lifecycle-viewmodel-2.5.0-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.0) and lifecycle-viewmodel-ktx-2.3.
Read more >
Prevent duplicate values in a table field using an index
Set the field's Indexed property to Yes (No duplicates) You can do this by opening the table in Design view. This method is...
Read more >
Duplicate value when Observing from ViewModel #3 - GitHub
Hi sir, I am trying to observer two LiveData but the values are set two times and make it has duplicate value. My...
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