Skip to content

[OPENJPA-2968] Do not swallow failures around IdClass primary key values - #167

Open
rzo1 wants to merge 1 commit into
masterfrom
OPENJPA-2968
Open

[OPENJPA-2968] Do not swallow failures around IdClass primary key values#167
rzo1 wants to merge 1 commit into
masterfrom
OPENJPA-2968

Conversation

@rzo1

@rzo1 rzo1 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

The @IdClass extraction and reconstruction paths added for the JPA 2.4.1.3 example 2b case caught every exception and continued: on write the primary key columns were filled with nulls, on read the field was left null, so a corrupt identity could be persisted or loaded without a trace.

Both paths now raise a StoreException naming the field, the id class and the mapping, with the original failure chained. A null id class value on the write path is legitimate, so it still writes nulls, but logs a warning.

The columns are also no longer paired with the id class fields by Class.getDeclaredFields() order, which the JVM does not guarantee. Where every column names its target through referencedColumnName the fields are matched by that name; declaration order remains only as the fallback for mappings that provide no name, since that is all such a mapping offers.

TestDerivedIdEx2c covers the ordering: its id class declares the fields in the order opposite to the join columns, so a find() misses on the previous code and succeeds now.

The @IdClass extraction and reconstruction paths added for the JPA 2.4.1.3
example 2b case caught every exception and continued: on write the primary
key columns were filled with nulls, on read the field was left null, so a
corrupt identity could be persisted or loaded without any trace. Both paths
now raise a StoreException naming the field, the id class and the mapping,
with the original failure chained, and a null id class value on the write
path is logged as a warning.

The columns are also no longer paired with the id class fields by
Class.getDeclaredFields() order, which the JVM does not guarantee. Where
every column names its target through referencedColumnName the fields are
matched by that name; the declaration order remains only as the fallback
for mappings that provide no name.

TestDerivedIdEx2c covers the ordering: its id class declares the fields in
the order opposite to the join columns, so a find() misses on the previous
code and succeeds now.
@rzo1 rzo1 self-assigned this Aug 29, 2026
@rzo1
rzo1 requested review from cristof and solomax August 29, 2026 17:54

@solomax solomax left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just minor comments :)

for (int c = 0; c < mic.size(); c++) {
if (cols.length == 1) rvals.add(null);
else ((Object[]) rvals.get(0))[idx++] = null;
List<java.lang.reflect.Field> df =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird enough java.lang.reflect.Field is not moved to import's

}
} else {
Log log = fms[i].getRepository().getLog();
if (log.isWarnEnabled())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add {} here :)


private static java.lang.reflect.Field findField(
List<java.lang.reflect.Field> fields, String name) {
for (java.lang.reflect.Field f : fields)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add {} in these for/if's :))

Is the stream API will be slower here? :)
like: fields.stream().filter(f -> f.getName().equals(name)).findFirst().orElse(null)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants