Question

I have a small schema consisting of ~10 classes mapped by jpa2 with hibernate as provider. All of the classes are build in the same basic way (@Entity annotation for the class, id with @Id and @GeneratedValue). All classes have default constructors and default getter/setters.

All but one of the classes are in a relation to one another (via associations or inheritance). And this one class does not get a database table created in the database during the schema generation process.

I've tried the following settings with hbm2ddl.auto:

create: All tables but the one are created. When the entity is accessed for the first time an exception is thrown: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table '...' doesn't exist (or the oracle equivalent if the code is run on Oracle DB).

validate: hibernate complains about the missing table during schema validation.

update: The table does not get created and an exception (like with create) is thrown the first time an entity of that class is accessed.

Has anyone any idea on this?

Was it helpful?

Solution

Try the following: modify the class of that Entity to only have the id field. Make sure the class is annotated with @Entity at the id field is annotated with @Id. Make sure this entity is declared in the list of mapped-classes (or is in a package that is declared amongst the mapped packages). Add "TRACE" level logging to "org.hibernate" via log4j.xml. Start a hibernate session (start your app), and look in the log for the statements Hibernate generates for the creation of the schema. If the table is missing from there, then you're not configuring the bean correctly and hibernate is not considering it as being part of the model. If the sql for the creation of the corresponding table is there, but there's an error when it's executed, see what that SQL actually contains, this might help you find out what hibernate doesn't like. When the "empty" bean is finally created, start adding the properties/associations to it one at a time and redo the same check as before. At some point you'll get an error when you add a certain something, and you need to look for a solution from there.

OTHER TIPS

Stupid, stupid me. I have used an sql-keyword (update) as a name for a member-variable of the class.

I assumed the ORA-01747 message wanted to tell me about a failing select, but instead a closer look revealed that it actually pointed out as to why the table was not created at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top