Re: [Hibernate] AssertionFailure null id in entry
Stefanie Ertheld wrote:
[b]Hibernate version:3.2[/b]
[b]Name and version of the database you are using:Mysql 4[/b]
Hi, I got a Table I want to insert data into. It's primary key is an
auto increment id. Addionally, it has a unique key, that is based on two
columns.
When I try to insert a row that contains data that would violate the
unique key constraint, I get an error like: AssertionFailure null id in
entry
This is really weird, as this doesn't really seem to have anything to do
with the unique key???
There are two unique keys. It has to do with one of them.
Well, I am thinking - the Hibernate Model class uses Hibernate
assertions to model the table's structure, but the info of the unique
key was left out (legacy code! ;-). Could this be the reason for the
hard to understand error "null id in entry"? Maybe Hibernate tries an
insert, doesn't expect any violation as it doesn't know of the unique
key that exists on the table, then it maybe tries to retrieve the
automatically generated id Integer, which can not be generated, and
maybe THIS produces the error I receive?
Maybe you have an explanation that makes more sense???
Your explanation makes the most sense to me. You aren't specifying any value
for the id, and Hibernate apparently doesn't have any @Id notation for that
id, so the inserts are trying to give a NULL value for the id, it seems. Why
MySQL doesn't cover that is a mystery to me - maybe Hibernate is explicitly
trying to insert NULL for the id, thus defeating the id sequencer and causing
the "null id in entry".
Since you provide absolutely no code or error-message context it's only
speculation on my part. If you provide an SSCCE [1]
<http://www.physci.org/codes/sscce.html>
or at least, uncut unedited error messages and the relevant table definitions
and Hibernate annotations, we can help better.
[1] Andrew expands this as "Short, Self-Contained, Correct (Compilable)
Example." I prefer "Compilable" to "Correct" for the expansion of the second
"C". "Correct" in this instance means, "generates the error message of interest".
--
Lew