質問

I just switched my persistence.xml from

<property name="toplink.ddl-generation" value="drop-and-create-tables"/>

to

<property name="toplink.ddl-generation" value="create-tables"/>

and now data persists between application runs, as I would expect. However, this isn't quite the way I would expect this setting to work. Shouldn't drop-and-create only create when the table is missing or mismatched?

I'm just wondering whether this is standard, or perhaps an indication that I'm not using JPA correctly, that the table gets nuked too easily when drop-and-create is set.

役に立ちましたか?

解決

this is intended behaviour.

create-tables will only attempt to create tables, if the table already exists then it will not be dropped or replaced, the existing table will be used. This does not check if the table matches the one you try to create - just if a table with the given name exists. If your scheme changes you'll have to drop the table manually (or through another machanism) so it's newly created the next time.

drop-and-create-tables will first drop the existing table, and then create the new table. Note that this will loose all of the data in the tables when they are dropped.

他のヒント

Yes, I think your observations are correct. At least I had the same problems. It would be great if there were another option with your described behaviour.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top