1

Please help me resolve this issue. I tried googling for a solution and couldn't find one for this.

Table structure

Table: Catalog catalog_id (primary key) name

Table: Catalog_Locale catalog_id locale_id sequence composite key(catalog_id,locale_id)

Class

public Class Catalog{

@Id
@Column(name = "CATALOG_ID", nullable = false)
private String catalogId;

@Column(name = "NAME")
private String name;

    @OneToMany(targetEntity = CatalogLocale.class,fetch=FetchType.LAZY)
@JoinColumn(name = "CHILD_CATALOG_ID", nullable = false)
@Cascade(value = {})
protected List<CatalogLocale> locales = new ArrayList<CatalogLocale>(10);

    public void setCatalogId( String catalogId ){

    this.catalogId = catalogId;
}

    public void setName( String name ){

    this.name = name;
}

    public void setLocales( List<CatalogLocale> locales ){

    this.locales = locales;
}

    public void getCatalogId(){

    return catalogId;
}

    public void getName(){

    return name;
}

    public void getLocales(){

    return locales;
}

}

public class CatalogLocale{

@EmbeddedId
CatalogLocalePk catalogLocalePk;

@Column(name = "SEQUENCE")
private int sequence;

public void setCatalogLocalePk( CatalogLocalePk catalogLocalePk ){

    this.catalogLocalePk = catalogLocalePk;
}

public void setSequence( int sequence ){

    this.sequence = sequence;
}

public CatalogLocalePk getCatalogLocalePk(){

    return catalogLocalePk;
}

public int getSequence(){

    return sequence;
}

@Embeddable
public static class CatalogLocalePk{


    @Column(name = "CATALOG_ID", nullable = false)
    private String catalogId;

    @Column(name = "LOCALE_ID", nullable = false)
    private String localeId;

    public CatalogLocalePk(){

    }

    public CatalogLocalePk( String catalogId, String localeId ){

        this.catalogId = catalogId;
        this.localeId  = localeId;
    }

    public void setCatalogId( String catalogId ){

        this.catalogId = catalogId;
    }

    public void setLocaleId( String localeId ){

        this.localeId = localeId;
    }

    public String getCatalogId(){

        return catalogId;
    }

    public String getLocaleId(){

        return localeId;
    }
}

}

The code works for fine for the insert operation, but for any update to the Catalog will trigger for delete and reinsert all entries of the child table.

Is there any solution for this?

4

0 回答 0