Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Problem adding related entities with Hibernate

    Hello,
    I'm working with SmartGWT 3.0p with HibernateDataSource (using schemabean).
    I have a problem with related entities when I try to add an owned entity (detail), foreign keys that are described in the datasource are not filled. When I save I get a constraint violation exception. I have to set these FKs as not required in the database in order to not receive this exception, but the fields stay NULL. The only way I've found to fix this is to switch the related fields to plain Long fields.

    Client side code to reproduce the problem (datasources included in attachments)
    Code:
                    Record venda = new Record();
    		venda.setAttribute("descricao", "Venda X");
    		
    		RecordList itensVenda = new RecordList();
    		
    		Record itemVenda = new Record();
    		itemVenda.setAttribute("produto", 1);
    		itensVenda.add(itemVenda);
    		
    		venda.setAttribute("itens", itensVenda);
    
    		// Tested in informix and mysql FK has 
    		DataSource.get("venda").addData(venda);
    Attached Files

    #2
    Hi,

    As I've understood - you have OneToMany bidirectional relation:
    venda->itemVenda
    Active part is venda.

    You have to correct venda DS definition:
    Code:
    <field name="itens" type="itemVenda" multiple="true" foreignKey="itemVenda.venda"></field>
    to
    Code:
    <field name="itens" type="itemVenda" multiple="true" foreignKey="itemVenda.id"></field>
    Regards,
    Alius

    Comment

    Working...
    X