How is SQLContainer designed to handle joined database tables?
I have been exploring a bit in the source code and for example in SQLContainer.java line 1023:
/*
* Make sure not to add the same colName twice. This can easily
* happen if the SQL query joins many tables with an ID column.
*/
if (!propertyIds.contains(colName)) {
propertyIds.add(colName);
}
So not all columns are added to the container?
Or how would you handle table joins?
Is there a way to differentiate between ambiguous database columns? Like in plain SQL to prefix columns with the tablename:
SELECT tableA.id, tableB.id FROM tableA LEFT JOIN tableB ON...
I could of course add ‘generated columns’ but then a lot of extra query’s are generated and I lose sorting and filtering capabilities…
Sorry for the (very) long response time. Your problem seems to be due to the quoting of the column names by default. This causes problems when you have a joined table and generates the column identifiers as “tablename.columnname” instead of the correct “tablename”.“columnname”. This is a bug and I created
#7756 for it. In the meantime you can disable the quoting by adding this line to your FreeformStatementDelegate constructor:
As for the more general question, it is correct that SQLContainer only supports unique property IDs. If you require to show both, you should “rename” the colliding IDs in your query. An example:
SELECT tableA.id AS a_id, tableB.id AS b_id FROM tableA LEFT JOIN tableB ON...
The above query will, when in an SQLContainer attached to a table, render the columns “a_id” and “b_id” in the table.
I’m quite sure this can be done by the sql query container and the jpa container. Another container that supports this is the
JPA 2.0 Criteria Lazy Container add-on supports the BeanTupleContainer exactly for that purpose (joined tables)
thanks jean for reply but i am looking for working example for sqlContainer can you help with that.
Also I want to know how to use addReference() ,getReferencedItemId(),getReferencedItem(),setReferencedItem()
Currently i am not able to understand these and how to use these.
There’s an example of this in the AddressBook demo (
browse source ). The relationship between Person and City is handled in the example. This demo application is described in the
SQLContainer tutorial .
I’m trying to implement the solution you posted for the tree (using SQL Container), and eclipse throws me errors in “ComparisonType” and in “addFilter”. Also, I don’t get where you do the connection with the table…
The Filtering API was redesigned in Vaadin 6.6 and SQLContainer dropped the old custom filtering API and moved to completely use Vaadin’s filtering API. This happened after Manvel’s posts, so this is probably why you get error messages on those lines. See
the com.vaadin.data.util.filter package for more info on Vaadin filtering.
Hi there,
I’ve got a problem with the SQLContainer add-on when running the application with concurrent users. When an user applies a filter on SQLContainer, data change for other users too. Any idea about how to solve this?
I hope you can help me. Thank you very much in advance
Do you, by any chance, store the reference to the SQLContainer in a static field? Or is it accessed through a static field?
This means that all users of the application will use
the same instance of the SQLContainer for everything, which would explain why
you are seeing the same filters being applied to all users.
I´d like to know, if there is any chance to escape table names with a grave accent (`) as it is quiet usual to do this in mysql.
I already tried with DefaultSQLGenerator(“", "”), wich wont work and even a TableQuery with a table name like “right” will change the table name to an empty string.
As you can see my tables name is “right”, wich is an SQL constant. But a statement like “SELCT * FROM right” would - of course - work.
I am encountering an issue while committing the updated row back to the table by calling commit(). Well commit() method is not working as expected and its not committing the data back to table.
I have posted the details in the following thread, please help me out. Thanks.