I annotated a bunch of POJO's so JPA can use them to create tables in Hibernate. It appears that all of the tables are created except one very central table called "Revision". The Revision class has an @Entity(name="RevisionT")
annotation so it will be renamed to RevisionT so there is not a conflict with any reserved words in MySQL (the target database).
I delete the entire database, recreate it and basically open and close a JPA session. All the tables seem to get recreated without a problem.
Why would a single table be missing from the created schema? What instrumentation can be used to see what Hibernate is producing and which errors?
Thanks.
UPDATE: I tried to create as a Derby DB and it was successful. However, one of the fields has a a name of "index". I use @org.hibernate.annotations.IndexColumn
to specify the name to something other than a reserved word. However, the column is always called "index" when it is created.
Here's a sample of the suspect annotations.
@ManyToOne
@JoinColumn(name="MasterTopID")
@IndexColumn(name="Cx3tHApe")
protected MasterTop masterTop;
Instead of creating MasterTop.Cx3tHApe
as a field, it creates MasterTop.Index
. Why is the name ignored?
If the table name/field name name is as same as the table name/column name, then you don't have to specify the name attribute. Here, we specify create for the hibernate. hbm2ddl. auto property so Hibernate will create a table from the entity class.
For this reason, the ability to have JPA frameworks -- such as EclipseLink or Hibernate -- create tables and databases as they bootstrap is built right into the specification. These database creation facilities are also a great way to validate a newly set up Hibernate and JPA development environment.
Not with Hibernate. It requires a primary key.
In case this helps anybody, this happened to me today and it turned out I was using a reserved word on my entity definition:
@OneToMany(mappedBy="list")
@OrderColumn(name="order")
private List<Wish> wishes;
"order" in this case, and Hibernate just skipped over this class. So check your user defined names! :)
Cheers, Mark
Answer to your side question (What instrumentation can be used to see what Hibernate is producing and which errors?)
You can org.hibernate.tool.hbm2ddl.SchemaExport
to generate your tables.
AnnotationConfiguration conf = (new AnnotationConfiguration()).configure();
new SchemaExport(conf).create(showHql, run);
The first argument allows you to see which HQL this command generates (CREATE TABLE
s etc). The second one is whether it should actually perform any modifications (ie false = dry-run).
So running it with (true, false)
will show you exactly what Hibernate would do to your tables, without changing anything.
name attribute on @Entity
is not what you want to use for this purpose. Use @Table
annotation instead:
@Entity
@Table(name="RevisionT")
public class Revision {
It is due to column names matches with your underlying Database sql reserved words.....try by changing name of columns.....i had faced same problem by changing names it did work.
For me it was a syntax mistake in columnDefinition. Easily detectable by the debug logs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With