Hi all:
I've seen people encountering similar error messages, but the cause of mine doesn't seem to be similar to any of theirs. Any pointers on how to solve this or an explanation on what's going on is greatly appreciated! Here are the tables from my legacy DB:
Code:
CREATE TABLE table_a (
a_id int(10) unsigned NOT NULL AUTO_INCREMENT,
x tinyint(3) unsigned NOT NULL,
PRIMARY KEY (a_id,x),
)
CREATE TABLE table_b (
b_id int(10) unsigned NOT NULL AUTO_INCREMENT,
x tinyint(3) unsigned NOT NULL,
a_id int(10) unsigned DEFAULT NULL,
PRIMARY KEY (b_id,x),
KEY fk_table_b_table_a1 (a_id,x),
CONSTRAINT fk_table_b_table_a1 FOREIGN KEY (a_id, x) REFERENCES table_a (a_id, x),
)
And the following were generated using Hibernate Reverse Engineering, truncated for brevity:
Code:
@Embeddable
public class TableAId {
private int a_id;
private byte x;
}
@Entity
@Table(name = "table_a")
public class TableA {
@AttributeOverrides({
@AttributeOverride(name = "a_id", column = @Column(name = "a_id", nullable = false)),
@AttributeOverride(name = "x", column = @Column(name = "x", nullable = false))
})
@EmbeddedId
private TableAId id;
}
@Embeddable
public class TableBId {
private int b_id;
private byte x;
}
@Entity
@Table(name = "table_b")
public class TableB {
@AttributeOverrides({
@AttributeOverride(name = "b_id", column = @Column(name = "b_id", nullable = false)),
@AttributeOverride(name = "x", column = @Column(name = "x", nullable = false))
})
@EmbeddedId
private TableBId id;
@JoinColumns({
@JoinColumn(name = "a_id", referencedColumnName = "a_id", nullable = false, insertable = false, updatable = false),
@JoinColumn(name = "x", referencedColumnName = "x", nullable = false, insertable = false, updatable = false)
})
@ManyToOne(fetch = FetchType.LAZY)
private TableA TableA;
}
Whenever I do an insert of TableB, I'm getting an error that says, "Field 'a_id' doesn't have a default value."
Removing _all_ "nullable=false" (why all? If not, I'd get a different error: "Mixing nullable and non nullable columns...") seems to "fix" it. But this is not optimal, because they _are_ non nullable. Many thanks in advance!