You may all have achieved Borg Perfection, but I haven't. So without an available edit button I'll just have to elaborate further in a comment.
These are the mappings for which {{hbm2ddl}} generates {{NOT NULL}} constraints, despite my doing everything in my power to have these columns made nullable instead: {code:title=BadThing} @OneToOne(optional = true) @JoinColumns({ @JoinColumn(name = "id", referencedColumnName = "thing_id", nullable = true, updatable = true), @JoinColumn(name = "current_thing_data", referencedColumnName = "created", nullable = true, updatable = true) }) @MapsId("id") private BadThingData currentData; {code}
Generated schema: {code} sql> show columns from bad_thing; FIELD | TYPE | NULL | KEY | DEFAULT ID | BIGINT(19) | NO | PRI | (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_85A1C07C_67FF_454A_B608_465214803984) LOCK | INTEGER(10) | NO | | NULL NAME | VARCHAR(255) | NO | UNI | NULL CURRENT_THING_DATA | TIMESTAMP(23) | NO | | NULL {code}
And similarly for my tree-structure, where the root node _must_ have a null parent:
{code:title=BadItemNode} @ManyToOne(fetch = FetchType.LAZY, optional = false true ) @JoinColumns({ @JoinColumn(name = "tree_id", referencedColumnName = "tree_id", nullable = true, updatable = false), @JoinColumn(name = "parent_id", referencedColumnName = "item_id", nullable = true, updatable = false) }) @MapsId("id.treeId") private BadItemNode parent; {code}
{code} sql> show columns from bad_item_node; FIELD | TYPE | NULL | KEY | DEFAULT ITEM_ID | BIGINT(19) | NO | PRI | NULL TREE_ID | BIGINT(19) | NO | PRI | NULL PARENT_ID | BIGINT(19) | NO | | NULL {code}
I have generated workarounds with entities {{Item}} and {{ItemNode}}, but I am thinking that these are different examples of the same underlying problem.
Full class definitions with failing JUnit tests are included in the attached Maven project. (Note that the JUnit tests for the workaround entities run correctly).
|