views:

547

answers:

3

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?

+1  A: 

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 {
ChssPly76
Damn you beat me to it :P
Blake Pettersson
Good idea. It didn't help. :(
User1
A: 

Perhaps you're using the wrong annotation. Once I accidentally annotated an entity with @org.hibernate.annotations.Entity instead of @javax.persistence.Entity, and Hibernate just skipped it.

André Neves
I am using @javax.persistence.Entity. However, I do have a org.hibernate.annotations.IndexColumn. Could mixing annotations cause a problem?
User1
No, definitely not.
André Neves
+2  A: 

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 TABLEs 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.

André Neves
That helped enormously! I discovered that there was still an column called "Index" being created. Further investigation showed the @OneToMany side of the schema also had @IndexColumn(name="Index"). Hibernate ignored the @IndexColumn on the @ManyToOne. I'm still wondering why there's no output from Hibernate. Oh well. It works!
User1
Haha, I'm glad that helped :)
André Neves