0

I have an element collection on my class:

public class InstancePdo implements Comparable<InstancePdo> {

  @Id
  @Column(name = COLUMN_NAME_ID, columnDefinition = "UUID")
  private UUID id;

  @Id
  @Column(name = COLUMN_NAME_VERSION, columnDefinition = "int")
  private int version = -1;

  @ElementCollection(fetch = FetchType.LAZY)
  @CollectionTable(name = "settings", joinColumns = {
      @JoinColumn(name = COLUMN_NAME_ID, referencedColumnName = COLUMN_NAME_ID, nullable = false, updatable = true),
      @JoinColumn(name = "COLUMN_NAME_VERSION", referencedColumnName = COLUMN_NAME_VERSION, nullable = false, updatable = true) })
  private Set<SettingPdo> settings;
}

Now, the setting looks like this:

@Embeddable
@Table(
    name = "settings",
    uniqueConstraints = @UniqueConstraint(
        columnNames = { "id", "version", "key", "type" }))
public class SettingPdo implements Comparable<SettingPdo> {

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

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


  @Column(name = "value", columnDefinition = "CLOB NOT NULL", )
  @Lob
  @Convert(converter = JsonNodeStringConverter.class)
  private String value;
}

Now, from time to time if I replace an instancePDO with a Merge operation, a delete statement is generated like this:

Error Code: 932
Call: DELETE FROM settings WHERE ((((((key = ?)) AND (type = ?)) AND (value = ?)) AND (id = ?)) AND (version = ?))
        bind => [4 parameters bound]

Now, the problem is that Oracle does not accept a WHERE clause on a CLOB (or any other LOB) column. I drained all stack overflow reading all similar threads like this: https://stackoverflow.com/a/33833399/1549977

If you use a Set and make the element Column be not null, then hibernate will make a primary key with the join column and element column.

As you can see, Eclipselink will still generate delete statements which contains comparisons on a CLOB field.

Hashcode an equals are also correct.

I have no idea what to do next. What's wrong with my classes (or database, for that matter)? As I am stuck with Oracle, how can I force JPA not to include some specific columns in a delete statement?

Thanks in advance!

Benjamin Marwell
  • 1,173
  • 1
  • 13
  • 36
  • I mean, I always thought that on change all items from the element connection get deleted and re-inserted. Why does JPA try to delete specific elements here? And if so, why try to use it's value? – Benjamin Marwell Oct 30 '17 at 09:02
  • Check that you are using the latest EclipseLink and that the target database platform is set (https://www.eclipse.org/eclipselink/documentation/2.4/jpa/extensions/p_target_database.htm ). This occurs because elements of the collection don't have an id to use to determine which to delete. You could workaround it by making the target an entity – Chris Oct 30 '17 at 16:58
  • I'm using IBM liberty profile and open liberty, so no choice about updating. As an entity or works. But it is not an entity imho. I could create a PMR of you think this is a bug. – Benjamin Marwell Oct 30 '17 at 17:01

0 Answers0