Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
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:
// Create containers for the 2 entity-types
JPAContainer<TestEntity> container = JPAContainerFactory.make(TestEntity.class, ...pu...);
JPAContainer<TestEntity2> 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());
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:
<!ENTITY vaadin.version "7.3.10">
<dependency org="com.vaadin.addon" name="jpacontainer" rev="3.2.0" />
<dependency org="org.eclipse.persistence" name="eclipselink" rev="2.6.0" conf="default"/>
<dependency org="mysql" name="mysql-connector-java" rev="5.1.35" />
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.