I created an object, InvoiceItem, that I wanted to persist and gave it an "Integer index" field, with Integer getIndex() and void setIndex() public methods. This object was then referenced by the Invoice class in a SortedSet<InvoiceItem> field. The SortedSet<InvoiceItem> field had the following annotation:
@OneToMany( cascade = CascadeType.ALL, fetch = FetchType.EAGER )
@JoinTable(name = "vgs4_join_invoice_to_invoice_item", joinColumns = { @JoinColumn(name = "invoice_id") }, inverseJoinColumns = { @JoinColumn(name = "invoice_item_id") })
@Sort( type = SortType.NATURAL )
Upon starting my program, I got Hibernate errors telling me of an SQL syntax error. Took a bit of looking around and copy-pasting the SQL into a terminal to realize that "index" is a MySQL keyword. Changed field to "invoiceIndex" and the problem went away.
I dunno anything about the Hibernate source, but this issue should simply be a matter of throwing a specific, detailed error if a field named "index" is detected and MySQL (or any other database with "index" as a reserved word) is in use.
|