Hello Adriano,
No. It should not be working this way and thanks for finding this bug!
The fact that a new Cart was added to the graph is recorded in the SDO
change summary and indicates to the DAS that an INSERT should be
generated. However, it looks like the DAS then generates the insert
statement based solely on attributes that have been set. I just tested
this and an invalid insert statement is generated which results in the
database throwing a SQLException; I assume you get a similar error.
I think there are two possible correct behaviors for this:
1. The DAS always generates a complete INSERT statement using
whatever values exist in the new DataObject. If a property has
not been set then these values will be null for object properties
or default values for primitive properties.
2. The DAS generates a partial INSERT whenever there are set
properties and generates a complete INSERT otherwise
My guess is that the first option will be most straightforward for users
to understand and will lead to least astonishment.
Any thoughts folks?
In the meantime, Adriano, can you set some property of the new item you
want inserted?
I created TUSCANY-957 to track this.
Thanks.
--
Kevin
Adriano Crestani wrote:
I created one table called "cart" with an auto-increment key on mysql,
then
I defined this table on the config.xml as containing an auto-increment
key.
Using SCO/DAS I create one tuple of the "cart" table, but no attribute is
set. I know DAS only update one attribute tuple only if it has been
modified
and if no attribute is set the tuple should not be added in the database,
but it is implicit that at least one attribute will be set, in this
case the
primary key, cause it is set as auto-increment key. Unfortunately the
tuple
is not being added in the database : (. Should it be working this way?
Here is the code that tries to create a new cart tuple in the database:
public void newCart() {
DAS das = DAS.FACTORY.createDAS
(getClass().getClassLoader().getResourceAsStream("ShoppingCartConfig.xml"),
getConnection());
Command command = das.getCommand("all carts");
DataObject allCarts = command.executeQuery();
DataObject newCart = allCarts.createDataObject("CART");
allCarts.getList("CART").add(newCart);
das.applyChanges(allCarts);
}
How the table "cart" is being declared in the mysql database:
CREATE TABLE CART (
ID INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
SUB_TOTAL DOUBLE,
TAX DOUBLE,
TOTAL DOUBLE,
CONFIRMED INTEGER
);
ShoppingCartConfig.xml:
<?xml version="1.0" encoding="ASCII"?>
<Config xmlns="http:///org.apache.tuscany.das.rdb/config.xsd">
<Command name="all carts" SQL="SELECT * FROM CART" kind="Select"/>
<Table tableName="CART">
<Column columnName="ID" primaryKey="true" generated="true"/>
</Table>
</Config>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]