Oracle 12c / SAP Hana insert fails when entity contains only an identity-based column.

Description

There are a variety of ways to define an entity mapping that only consists of a single identity-based column, such as:

or

In either case, the generated insert SQL syntax is incorrect.

For Oracle 12c, the generated SQL is

This should probably by rendered instead as

I'm unclear on the exact fix (if any) for SAP Hana.

Environment

None

Activity

Show:
Jonathan Bregler
December 19, 2018, 9:04 PM

While it's true, that HANA currently doesn't support inserting a single value into an auto-generated column, it feels to me like throwing a MappingException seems to be too strict. The reason is that Dialect.getNoColumnsInsertString is called while creating the EntityPersister. So now entities mapping to a table with just one auto-generated column block the creation of a session, although the INSERT query may not even be executed.

You can check this behavior, for example, by running org.hibernate.jpa.test.ops.GetLoadTest.

I would prefer not throwing a MappingException and having the user run into a SQL query exception instead, because it doesn't unnecessarily block the creation of sessions.

Vlad Mihalcea
December 19, 2018, 9:54 PM

I think it's ok to notify the user as fast as possible that the INSERT will not work. I only think we should fix the tests and add support in DialectChecks for this. Maybe introduce a new supports method. I'll reopen the issue for this reason.

Jonathan Bregler
December 19, 2018, 10:16 PM

OK, if you think Hibernate should behave this way, I guess it's fine. I was just pointing out that there might be a use-case for just reading from a table like this without ever inserting data, which isn't possible any more after this fix. I'll think about maybe adding a parameter for switching back to the old behavior.

Vlad Mihalcea
December 20, 2018, 12:10 AM

The only situation when this could happen is if you have an entity with just an identifier. Therefore, in real life, I don't see how you'd end up with such a table.

Once you have at least one property in the entity, the INSERT will work just fine.

Jonathan Bregler
December 20, 2018, 3:34 AM
Edited

I could think of a migrated persistence from another database where this was a valid scenario. A user might be fine just reading from that persistence at first to see if the application can work on HANA. With the fix, a user would have to migrate the application first. But this is probably a corner case that doesn't happen too often.

Fixed

Assignee

Chris Cranford

Reporter

Chris Cranford

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major