hibernate.hbm2ddl.auto=create does not drop tables

Description

Setting <property name="hibernate.hbm2ddl.auto" value="create" /> does not drop tables previous to creating them. That was the behavior up to at least 3.6.0 and was extremely useful for test cases.

To reproduce, run attached test case twice.

08:27:44,503 [main] DEBUG SqlStatementLogger - create table Customer (id int8 not null, primary key (id))
08:27:44,504 [main] ERROR SchemaExport - HHH00389:Unsuccessful: create table Customer (id int8 not null, primary key (id))
08:27:44,504 [main] ERROR SchemaExport - ERROR: relation "customer" already exists
08:27:44,505 [main] INFO SchemaExport - HHH00230:Schema export complete

Environment

None

Activity

Show:
Alexandre Gattiker
August 17, 2011, 11:13 AM

No: "With create-drop, the database schema will be dropped when the SessionFactory is closed explicitly."

The behaviour of "create" up to 3.6.0 was to drop tables if they already existed, before creating them.

Steve Ebersole
August 17, 2011, 7:05 PM

Right, this is a bug if true and certainly a regression as you mention. But it will not make today's release cut.

Lukasz Antoniak
August 19, 2011, 11:01 PM

The issue has been assign, but I think I have fixed it. See pull request: https://github.com/hibernate/hibernate-core/pull/155.
I did not want to interrupt your work Gail.

Gail Badner
August 20, 2011, 2:40 AM

Lukasz, sorry, didn't know you were working on it until I was about to commit my fix.

I see that your pull request makes changes to how SessionFactoryImpl uses SchemaExport.

I've created a pull request that restores the 3.6 behavior, where SchemaExport.create() executes the drop script before executing the create script:
https://github.com/hibernate/hibernate-core/pull/156

Steve, you decide which is preferred.

Gail

Jeff Yu
October 5, 2011, 10:27 AM

Hi,

Firstly, sorry to make a comment on a "CLOSED" jira, however, due to this fix, I am having an ERROR message shows those tables were not existed on running drop scripts. (the drop table is fine, as they mostly will include the 'if exists', but before dropping the table, it will drop those foreign key constraints), detailed please see my thread in Hibernate forum. https://forum.hibernate.org/viewtopic.php?f=1&t=1012898

Thanks
Jeff

Assignee

Steve Ebersole

Reporter

Alexandre Gattiker

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure