Multiple bags Exception / Searching multiple collections with JPA

0

I'm having a problem with JPA when it comes to making a query.

I want to query Entity A that has a% of Entity% B and% of Entity% C (I want to query Entity A by bringing Entities B and C into the same List ). >

When I try to execute this query the multiple bags exception is thrown.

Is there any way to do this query without having to use List , query or change @IndexColumn to Fetch.EAGER ? (Solutions I found on the internet)

NOTE: I did not put the code here because I just want to know if there is an alternative other than the one I mentioned earlier.

    
asked by anonymous 11.07.2018 / 04:54

1 answer

0

The most common cause for this error is when you try to make 2 (or more) JOIN s using FETCH , each of which JOIN s is by List . >

Let's take an example. Given the (pseudo) entities:

@Entity
class Entidade1 {
    private List<Entidade2> entidades2;
}

@Entity
class Entidade2 {
    private List<Entidade3> entidades3;
}

The following JPQL will reproduce the problem:

SELECT e1 FROM Entidade1 e1
JOIN FETCH e1.entidades2 e2
JOIN FETCH e2.entidades3 e3

The most common solution is this: change from List to Set the mapping of entidades2 and entidades3 . The solution with EAGER I would not even consider, so much the consequence that it can bring to the application.

Or, if possible, avoid using JOIN FETCH from another. As far as I know, only Hibernate supports alias in JOIN FETCH , allowing this type of situation and error.

So the solution I recommend is to consider using a VO , bringing only what you need from the 3 entities:

SELECT new br.com.EntidadeVO(e1.id, e1.nome, e2.id, e3.nome) FROM Entidade1 e1
JOIN e1.entidades2 e2
JOIN e2.entidades3 e3
    
27.07.2018 / 17:40
___ ___ erkimt Python - Tkinter - Dynamic CheckButton not take the value of the variable when referenced from another file / screen ______ qstntxt ___

I'm having the following problem: I can get the value of a dynamic variable (checkbutton) when the whole program is in a single file with only one function:

%pre%

However if I separate the code into two files, each one on a screen and two modules, I can only get the 0 values of the checkboxes:

File 1: TwoWindows2

%pre%

File 2: TwoWindows2

%pre%

Can anyone help me with this?

    
______ azszpr313528 ___

Variables from the other file can be accessed normally if you import the other file - but not with the %code% syntax, and use the filename as a prefix:

For example, you could put all the variables in a file name %code% and use a line like this

%pre%

And inside that file you can access the variables with %code% and so on.

Your code is pretty messy, but sometimes doing is the only way to learn - I recommend a third file, why else can you to fall into a problem of circular import dependency, the way it is working.

Another note: The keyword "global" only makes sense within functions - and says that those variables within the function will be visible in that module (file) - (and thus will be visible from the other files using the form prefix, as I showed above): using "global" inside classes and outside functions does not make sense. (It would even make a difference, but one has to know a lot Python to know exactly what it is doing, and even then, it would hardly be the right way to do anything.)

    
___
IONIC using nativeAudio