When you recently used Hibernate's dynamic build table in your project to configure Hbm2ddl.auto as update, you found that hibernate did not generate the corresponding data table information according to the default build rules. Strangely, however, only some of the tables were not generated, while the other tables were generated successfully. Reboot the project and find the problem remains. Oddly, although some tables are not generated, the associated tables that are associated with them are generated, and at build time, an error is reported that cannot find the associated reference table. The reported errors are as follows:
2014-09-28 01:25:56 [org.hibernate.tool.hbm2ddl.schemaupdate]-[error] unsuccessful:alter table R_role_x_menu add Constraint fk474dc862e1a553e2 foreign KEY (menu_id) references P_menu 2014-09-28 01:25:56 [ Org.hibernate.tool.hbm2ddl.schemaupdate]-[error] ORA-00942: Table or view does not exist
Looking for a long time, finally found a problem, that is, the table to be referenced here P_menu in another user space already exists, and hibernate in the creation of the table, in another user space to find the table, so no longer in the current user space to create this table. This error occurs when the associated table is created because it is associated with a table for this user space.
Hibernate uses the JDBC default Databasemeta to find the appropriate table data information, and when using the default configuration, for some reason (not every time it happens, depending on the database itself and the corresponding driver). When you use the current user to connect to a database, when you use Databasemeta to look for database table information, the data table information for other users is queried (even if the current user does not have the appropriate permissions).
The solution to this problem is simply to configure one sentence in Hibernate.cfg.xml:
<property name= "Default_schema" > Current connection User </property>
This way, when using Databasemeta, it is mandatory to look for database information in the current user space, so that the table structure can be created correctly.