0

I have Embeddable class which look like this:

public class ClobEmbeddableValue {

    ...fields...

    @Lob
    @Type(type = "org.hibernate.type.MaterializedClobType")
    @Column(name = "clobValue")
    @Override
    public String getValue() { return value; }

    public String getChecksum() { return checksum; }

    ...other getters/setters...
}

and this is used in entity as

@ElementCollection
@ForeignKey(name = "fk_clob")
@CollectionTable(name = "m_clob", joinColumns = {
        @JoinColumn(name = "owner_id"), 
        @JoinColumn(name = "owner_oid"),
        @JoinColumn(name = "ownerType")})
@Cascade({org.hibernate.annotations.CascadeType.ALL})
public Set<ClobEmbeddableValue> getClobs() { return clobs; }

When I'm updating entity and/or it's clobs hibernate generates update/delete SQL query where all fields from Embeddable are present. I understand why it does this, but that is not very good in this case, because Hibernate tries to compare CLOB value with operator = Can I somehow tell hibernate to ignore field value (CLOB) and only use checksum (which was created for this purpose and it's md5 hash computed from clob, so it's good enough for comparing) in where clauses in queries? Or do you guys have other ideas how to solve this?

viliam
  • 503
  • 6
  • 23
  • 1
    Why don't you do the right thing, and make your embeddable an entity with an auto-generated ID. Hibernate wouldn't have to check all the fields and delete re-create the elements. It would just compare the IDs. Primary keys and IDs exist for a good reason. – JB Nizet Jan 24 '13 at 15:40
  • @JBNizet That would fix this, but are you saying that Embeddeables should be avoided in general? Personally, I like the distinction between Entity and Embeddable... – sharakan Jan 24 '13 at 15:55
  • Embeddables are fine when they're embedded in another entity, in order to group fields together in objects. I find them ugly when used in element collections. – JB Nizet Jan 24 '13 at 15:58
  • I can't create another entity with auto-generated ID, ID would be lost because I'm using session-per-request and DTO classes above are "fixed" for me, therefore I can't add ID there. – viliam Jan 24 '13 at 16:13

0 Answers0