JPAContainer problem with Or-Filter

Hi Folks,
when using JPAContainer with the Or-Filter, i get the same Items multiple times in the filtered container.
Here’s my sample code:

Test Entities:

@Entity
public class TestEntity {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Integer id;
    
    @ManyToMany
    private Collection<TestEntity2> testEntities2 = new HashSet<TestEntity2>();

    private String someField;

    getters/setters...
}

@Entity
public class TestEntity2 {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Integer id;
    
    private String someField;

    getters/setters...
}

Test Code:

[code]
// Create containers for the 2 entity-types
JPAContainer container = JPAContainerFactory.make(TestEntity.class, …pu…);
JPAContainer container2 = JPAContainerFactory.make(TestEntity2.class, …pu…);

// Create entities
TestEntity testEntity = new TestEntity();
// Add and retrieve to have Object with id set
TestEntity2 testEntity2ToAdd1 = container2.getItem(
container2.addEntity(new TestEntity2())).getEntity();
TestEntity2 testEntity2ToAdd2 = container2.getItem(
container2.addEntity(new TestEntity2())).getEntity();

// Add to collection
testEntity.getTestEntities2().add(testEntity2ToAdd1);
testEntity.getTestEntities2().add(testEntity2ToAdd2);

// Add to the container
container.addEntity(testEntity);

// Create an Or-filter for the just created TestEntity2-entities
Or or = new Or(
new Compare.Equal(“testEntities2.id”, testEntity2ToAdd1.getId()),
new Compare.Equal(“testEntities2.id”, testEntity2ToAdd2.getId()));

// Add the filter
container.addContainerFilter(or);

// Will output the ID of testEntity 3x
System.out.println(container.getItemIds());
[/code]This is the SQL-Statement created:
SELECT t0.ID FROM TESTENTITY_TESTENTITY2 t4, TESTENTITY_TESTENTITY2 t3, TESTENTITY2 t2, TESTENTITY2 t1, TESTENTITY t0 WHERE (((t1.ID = ?) OR (t2.ID = ?)) AND (((t3.TestEntity_ID = t0.ID) AND (t1.ID = t3.testEntities2_ID)) AND ((t4.TestEntity_ID = t0.ID) AND (t2.ID = t4.testEntities2_ID)))) ORDER BY t0.ID ASC

I am no SQL-Expert, but this select statement looks pretty odd to me.

If i add a third entity to the collection and append it to the Or-filter, testEntity is 19x in the container.
I tried Collection, Set and List as type of “testEntities2”.

Am i doing somethig wrong or is this a Bug?

The And-filter seems to work, allthough the SQL-Statement looks odd too…

Environment info:

Should be the newest version of all used libs

Thank you,
Felix

I worked around the problem by setting an QueryModifierDelegate an always make the queries distinct.
But i would be really interested if i found a bug or just having some faulty reasoning here.

Ok my workaround does not work properly… If you call container.size() you get of course still the “wrong” result and for example the table component is not usable…
Any help would be really appreciated!
I plan to move away from JPAContainer (because even some Vaadin Devs don’t like it) but for now i have to stick with it.