开发者

Hibernate with existing databases

开发者 https://www.devze.com 2023-02-08 08:04 出处:网络
I\'m trying to build a spring roo project using hibernate and an oracle database. The oracle database contains tables used by another application.

I'm trying to build a spring roo project using hibernate and an oracle database. The oracle database contains tables used by another application.

I have an entity User that already 开发者_StackOverflow中文版exists in the database, containing thousands of users and shared by another application.

My new roo project contains the user entity and also some others. The persistence.xml is configured with the following property:

<property name="hibernate.hbm2ddl.auto" value="update"/>

On the first deployment of the app, hibernate fails because there are no tables for the entities. Changing the value to "create" fixes this, but wipes the user table :(

Is there a way around this? What I would like to do is this

  1. property value is "create" but the User entity is excluded somehow
  2. Deploy application, tables are created etc. Existing User table is used.
  3. Stop application
  4. Modify property value to "update"
  5. No data loss :)

Many thanks.


There must be a better way to do this, but here is a quick hack which will get you rolling with your desired steps:

  1. Rename the table in your Hibernate mapping to user_unused
  2. Modify property value to create
  3. Deploy application, tables are created etc, existing user table is unaltered.
  4. Stop application
  5. Rename the table in your Hibernate mapping to user
  6. Modify property value to update
  7. Delete the user_unused database table that was created by Hibernate in step 1


I remember from some hibernate forum that this feature is not available yet from hibernate. So here is another hack. You may use false for 'creat' and true for 'update'. off-course you would be required to have all classes configured in that case.

0

精彩评论

暂无评论...
验证码 换一张
取 消