Question

We are encountering strange hibernate behavior with hbm2ddl.auto set to update.

In our test setup, we have two database users, one containing the tables for our beta application, the other one is mainly used for development. I.e. same table names with different users. When new tables are to be created, we do so by using hbm2ddl.auto=update.

Now suddenly the strange behavior is: the update process looks for existing tables with the wrong user and creates those not found with the right user.

E.g. if the following tables exists

USER_A.TABLE_1
USER_B.TABLE_2

and we update with three tables configured: TABLE_1, TABLE_2, TABLE_3 using USER_B, we end up with

USER_A.TABLE_1
USER_B.TABLE_2
USER_B.TABLE_3

TABLE_1 is not created for USER_B. After renaming USER_A.TABLE_1 to USER_A.TABLE_0 and updating again we end up with the expected result:

USER_A.TABLE_0
USER_B.TABLE_1
USER_B.TABLE_2
USER_B.TABLE_3

Does this make any sense to anyone? Is there something like an internal hibernate cache remembering like "Hey I have already created this table on this server (and I do not care about the user)".

We have spent quite some testing to reassure this is not a configuration problem, reproduced this on different machines, different configurations, from ant or using the IDE, making sure USER_A's password cannot be found anywhere in the build directory etc. So we are 100% sure, the behavior is as described - but we are completely out of ideas what happens.

I'd be very happy to hear your ideas about this, since this problem is nagging for some time now.

Thanks a lot, Peter

Was it helpful?

Solution

Is there something like an internal hibernate cache remembering like "Hey I have already created this table on this server (and I do not care about the user)".

No. What is probably happening is that USER_A can see the tables created under USER_B account, and vice-versa. It's not clear which database you are using, but I would try to configure Hibernate to use two different schemas, in addition to use just different users. You may also want to try to set the property "hibernate.default_schema", but I'm not sure that this only will solve your problem.

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