Hi Paul, I can’t use EntityComponents without fields.
I wanted to use some components just as flag, so they don’t store any value.
This works fine, as far as I don’t try to use the SqlEntityData. I tracked it down already to the class ComponentTable.
My fix seems to work, but it is not very tested yet.
Here are the changes:
In createInsertSql() i changed this line:
[java]
sql.append(", entityId");[/java]
to this:
[java]
sql.append((dbFieldNames.length > 0) ? “, entityId” : “entityId”);[/java]
and this
[java]
sql.append( ", ?");;[/java]
to this:
[java]
sql.append((dbFieldNames.length > 0) ? “, ?” : “?”);[/java]
So there are no commas in the sql when there shouldn’t be some.
In initialize() i changed this
[java] if (!dbFields.isEmpty()) {
checkStructure(defs, dbFields);
return;
}[/java]
to this
[java] if (!dbFields.isEmpty() || md.getTables("", “”, tableName, new String[]{“TABLE”}) != null) {
checkStructure(defs, dbFields);
return;
}[/java]
Because if I have a table with no data-rows, it wouldn’t be recognized as table and treated as if there wasn’t a table.
In getComponents() I added a condition:
[java] if (dbFieldNames.length == 0) {
sql.append(" * “);
}
Joiner.on(”, ").appendTo(sql, dbFieldNames);[/java]
Else it would do SELECT () FROM.
And in setComponent() I wrapped the part which tries the update into a
[java] if (fields.length > 0) {
///
}else{
if(getComponent(session, entityId)!= null){
return;
}
}[/java]
If the fields are empty, then there is not data which should be updated, it is just necessary to know if there is a component of this type or not, and if there is one, not to try to insert a new one.
As I said, it’s not exhaustively tested, but it worked at least once