Table not created by Hibernate

I annotated a bunch of POJOs, so JPA can use them to create tables in Hibernate. It appears that all the tables are created, with the exception of one central table called the "Revision". The Revision class has the @Entity(name="RevisionT") annotation @Entity(name="RevisionT") , so it will be renamed to RevisionT, so there will be no conflict with any reserved words in MySQL (the target database).

I delete the entire database, recreate it and basically open and close the JPA session. It seems that all tables are recreated without problems.

Why will there be no single table in the created schema? What hardware can I use to view what Hibernate produces and what errors?

Thanks.

UPDATE: I tried to create a DB DB Derby and was successful. However, one of the fields has the name "index". I use @org.hibernate.annotations.IndexColumn to specify a name for something other than a reserved word. However, a column is always called an “index” when it is created.

Here is an example of suspicious annotations.

 @ManyToOne @JoinColumn(name="MasterTopID") @IndexColumn(name="Cx3tHApe") protected MasterTop masterTop; 

Instead of creating MasterTop.Cx3tHApe , MasterTop.Index is created as a field. Why is the name ignored?

+4
source share
7 answers

Answer your question (what hardware can be used to view what Hibernate produces and what errors?)

You can org.hibernate.tool.hbm2ddl.SchemaExport generate your tables.

 AnnotationConfiguration conf = (new AnnotationConfiguration()).configure(); new SchemaExport(conf).create(showHql, run); 

The first argument lets you know which HQL command is generating ( CREATE TABLE , etc.). The second question is whether it should actually perform any modifications (i.e. false = dry-run).

Thus, running it with (true, false) will show you what Hibernate will do with your tables without changing anything.

+5
source

If this helps someone, it happened to me today, and it turned out that I used the reserved word to define my essence:

 @OneToMany(mappedBy="list") @OrderColumn(name="order") private List<Wish> wishes; 

"order" in this case, and Hibernate just skipped this class. So check your user-defined names! :)

Cheers, Mark

+5
source

the name attribute on @Entity is not what you want to use for this purpose. Use the @Table annotation @Table :

 @Entity @Table(name="RevisionT") public class Revision { 
+2
source

This is because the column names are the same as your basic SQL sql reserved words ..... try changing the column name ..... I ran into the same problem changing the names that it really worked.

+1
source

For me, it was a syntax error in columnDefinition . Easily detected by debug logs.

+1
source

You may be using the wrong annotation. As soon as I accidentally annotated an object with @org.hibernate.annotations.Entity instead of @javax.persistence.Entity , and Hibernate just skipped it.

0
source

Set the hibernate.show_sql config property to true and see if Hibernate generated the create table code. If so, copy the create statement to your database client (ui or command line) and see if your database returns an error.

For me, the mistake was not obvious until I did this.

I used the "condition" field, which was the reserved word MySQL. So check your field names ...

0
source

All Articles