Оговорююсь сразу, что использую mssql, что в принципе не должно влиять. И диалект установлен.
я думал, что если написать так:
1.
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
то схема у меня будет удаляться и создаваться заново перед запуском приложения.
Но оказалось, что если в базе есть данные, то hibernate не сможет это сделать и выплюнет что-то типа(мой вариант):
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180.
INFO ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@432a0f6c: startup date [Fri Sep 20 15:43:41 MSK 2013]; root of context hierarchy
INFO XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [test/BeanConfig.xml]
INFO XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [test/data.xml]
INFO DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@7971f189: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,candidateDao,eventDaoImpl,eventStatusDao,eventTypeDao,noteDao,skillDao,userDao,vacancyDao,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,transactionManager,dataSource,sessionFactory,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
INFO DriverManagerDataSource - Loaded JDBC driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
INFO Version - HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
INFO Version - HHH000412: Hibernate Core {4.2.1.Final}
INFO Environment - HHH000206: hibernate.properties not found
INFO Environment - HHH000021: Bytecode provider name : javassist
INFO Configuration - HHH000044: Configuring from URL: file:/C:/Users/Nikolay_Tkachev/workspace/HHSystem/Core/target/classes/test/hibernate.cfg.xml
INFO Configuration - HHH000041: Configured SessionFactory: null
INFO Dialect - HHH000400: Using dialect: org.hibernate.dialect.SQLServerDialect
INFO TransactionFactoryInitiator - HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
INFO ASTQueryTranslatorFactory - HHH000397: Using ASTQueryTranslatorFactory
INFO Version - HV000001: Hibernate Validator 4.3.1.Final
INFO SchemaExport - HHH000227: Running hbm2ddl schema export
Hibernate: alter table candidate drop constraint FK_05002f4935184e8dbd53c777ea8
ERROR SchemaExport - HHH000389: Unsuccessful: alter table candidate drop constraint FK_05002f4935184e8dbd53c777ea8
ERROR SchemaExport - FK_05002f4935184e8dbd53c777ea8 не является ограничением.
Hibernate: alter table candidate_skill drop constraint FK_c5663cc54c414c94b0612d5f96c
ERROR SchemaExport - HHH000389: Unsuccessful: alter table candidate_skill drop constraint FK_c5663cc54c414c94b0612d5f96c
ERROR SchemaExport - FK_c5663cc54c414c94b0612d5f96c не является ограничением.
Hibernate: alter table candidate_skill drop constraint FK_59cb93ba27dd41928c6771c5d5a
ERROR SchemaExport - HHH000389: Unsuccessful: alter table candidate_skill drop constraint FK_59cb93ba27dd41928c6771c5d5a
ERROR SchemaExport - FK_59cb93ba27dd41928c6771c5d5a не является ограничением.
Hibernate: alter table candidate_status drop constraint FK_6984215820fb413eb39dfd22be1
ERROR SchemaExport - HHH000389: Unsuccessful: alter table candidate_status drop constraint FK_6984215820fb413eb39dfd22be1
ERROR SchemaExport - FK_6984215820fb413eb39dfd22be1 не является ограничением.
Hibernate: alter table candidate_status drop constraint FK_e85dbd64c7064bfdbbeef9b4368
ERROR SchemaExport - HHH000389: Unsuccessful: alter table candidate_status drop constraint FK_e85dbd64c7064bfdbbeef9b4368
ERROR SchemaExport - FK_e85dbd64c7064bfdbbeef9b4368 не является ограничением.
Hibernate: alter table candidate_status drop constraint FK_784a44e94f8f46e484eded1872c
ERROR SchemaExport - HHH000389: Unsuccessful: alter table candidate_status drop constraint FK_784a44e94f8f46e484eded1872c
ERROR SchemaExport - FK_784a44e94f8f46e484eded1872c не является ограничением.
Hibernate: alter table event drop constraint FK_09d336cfb68b40feae3f77ffa96
ERROR SchemaExport - HHH000389: Unsuccessful: alter table event drop constraint FK_09d336cfb68b40feae3f77ffa96
ERROR SchemaExport - FK_09d336cfb68b40feae3f77ffa96 не является ограничением.
Hibernate: alter table event drop constraint FK_311eae80a3a5451a8e2b1d6e434
ERROR SchemaExport - HHH000389: Unsuccessful: alter table event drop constraint FK_311eae80a3a5451a8e2b1d6e434
ERROR SchemaExport - FK_311eae80a3a5451a8e2b1d6e434 не является ограничением.
Hibernate: alter table event drop constraint FK_986e9055821c4fcfbf6ef9622c2
ERROR SchemaExport - HHH000389: Unsuccessful: alter table event drop constraint FK_986e9055821c4fcfbf6ef9622c2
ERROR SchemaExport - FK_986e9055821c4fcfbf6ef9622c2 не является ограничением.
Hibernate: alter table event_candidate drop constraint FK_0691220128eb4670ab155d5b503
ERROR SchemaExport - HHH000389: Unsuccessful: alter table event_candidate drop constraint FK_0691220128eb4670ab155d5b503
ERROR SchemaExport - FK_0691220128eb4670ab155d5b503 не является ограничением.
Hibernate: alter table event_candidate drop constraint FK_6462e163ecb64a2ead602fefc88
ERROR SchemaExport - HHH000389: Unsuccessful: alter table event_candidate drop constraint FK_6462e163ecb64a2ead602fefc88
ERROR SchemaExport - FK_6462e163ecb64a2ead602fefc88 не является ограничением.
Hibernate: alter table event_vacancy drop constraint FK_6f021945d3024aaa9e02c32f06b
ERROR SchemaExport - HHH000389: Unsuccessful: alter table event_vacancy drop constraint FK_6f021945d3024aaa9e02c32f06b
ERROR SchemaExport - FK_6f021945d3024aaa9e02c32f06b не является ограничением.
Hibernate: alter table event_vacancy drop constraint FK_071e1fef728f4a8a9a90a24bab4
ERROR SchemaExport - HHH000389: Unsuccessful: alter table event_vacancy drop constraint FK_071e1fef728f4a8a9a90a24bab4
ERROR SchemaExport - FK_071e1fef728f4a8a9a90a24bab4 не является ограничением.
Hibernate: alter table note drop constraint FK_b0b5a59a7ebf4dd99e2ad14f1fb
ERROR SchemaExport - HHH000389: Unsuccessful: alter table note drop constraint FK_b0b5a59a7ebf4dd99e2ad14f1fb
ERROR SchemaExport - FK_b0b5a59a7ebf4dd99e2ad14f1fb не является ограничением.
Hibernate: alter table note drop constraint FK_f29149788d9b4f79b9a22c2c456
ERROR SchemaExport - HHH000389: Unsuccessful: alter table note drop constraint FK_f29149788d9b4f79b9a22c2c456
ERROR SchemaExport - FK_f29149788d9b4f79b9a22c2c456 не является ограничением.
Hibernate: alter table note drop constraint FK_691e0ff5a54248e48b31106dbd2
ERROR SchemaExport - HHH000389: Unsuccessful: alter table note drop constraint FK_691e0ff5a54248e48b31106dbd2
ERROR SchemaExport - FK_691e0ff5a54248e48b31106dbd2 не является ограничением.
Hibernate: alter table vacancy drop constraint FK_ae885d459b2f4349b8ab8412da1
ERROR SchemaExport - HHH000389: Unsuccessful: alter table vacancy drop constraint FK_ae885d459b2f4349b8ab8412da1
ERROR SchemaExport - FK_ae885d459b2f4349b8ab8412da1 не является ограничением.
Hibernate: alter table vacancy_candidate drop constraint FK_9f2264901e62465f82034f9a452
ERROR SchemaExport - HHH000389: Unsuccessful: alter table vacancy_candidate drop constraint FK_9f2264901e62465f82034f9a452
ERROR SchemaExport - FK_9f2264901e62465f82034f9a452 не является ограничением.
Hibernate: alter table vacancy_candidate drop constraint FK_91e1f95c7480439e84286f29364
ERROR SchemaExport - HHH000389: Unsuccessful: alter table vacancy_candidate drop constraint FK_91e1f95c7480439e84286f29364
ERROR SchemaExport - FK_91e1f95c7480439e84286f29364 не является ограничением.
Hibernate: alter table vacancy_skill drop constraint FK_fd280abba4e04e3abbf4a1095b4
ERROR SchemaExport - HHH000389: Unsuccessful: alter table vacancy_skill drop constraint FK_fd280abba4e04e3abbf4a1095b4
ERROR SchemaExport - FK_fd280abba4e04e3abbf4a1095b4 не является ограничением.
Hibernate: alter table vacancy_skill drop constraint FK_5c76545808be40d1a2d504aa838
ERROR SchemaExport - HHH000389: Unsuccessful: alter table vacancy_skill drop constraint FK_5c76545808be40d1a2d504aa838
ERROR SchemaExport - FK_5c76545808be40d1a2d504aa838 не является ограничением.
Hibernate: alter table vacancy_status drop constraint FK_144f29b0aa774611bdb2f96260b
ERROR SchemaExport - HHH000389: Unsuccessful: alter table vacancy_status drop constraint FK_144f29b0aa774611bdb2f96260b
ERROR SchemaExport - FK_144f29b0aa774611bdb2f96260b не является ограничением.
Hibernate: alter table vacancy_status drop constraint FK_233da02be659464db8e989d1a7a
ERROR SchemaExport - HHH000389: Unsuccessful: alter table vacancy_status drop constraint FK_233da02be659464db8e989d1a7a
ERROR SchemaExport - FK_233da02be659464db8e989d1a7a не является ограничением.
Hibernate: alter table vacancy_status drop constraint FK_cdfc1bd4591448cf8f47a23dbe7
ERROR SchemaExport - HHH000389: Unsuccessful: alter table vacancy_status drop constraint FK_cdfc1bd4591448cf8f47a23dbe7
ERROR SchemaExport - FK_cdfc1bd4591448cf8f47a23dbe7 не является ограничением.
Hibernate: drop table author
ERROR SchemaExport - HHH000389: Unsuccessful: drop table author
ERROR SchemaExport - Невозможно удалить объект "author", так как на него ссылается ограничение FOREIGN KEY.
Hibernate: drop table candidate
ERROR SchemaExport - HHH000389: Unsuccessful: drop table candidate
ERROR SchemaExport - Невозможно удалить объект "candidate", так как на него ссылается ограничение FOREIGN KEY.
Hibernate: drop table candidate_skill
Hibernate: drop table candidate_status
Hibernate: drop table event
ERROR SchemaExport - HHH000389: Unsuccessful: drop table event
ERROR SchemaExport - Невозможно удалить объект "event", так как на него ссылается ограничение FOREIGN KEY.
Hibernate: drop table event_candidate
Hibernate: drop table event_status
ERROR SchemaExport - HHH000389: Unsuccessful: drop table event_status
ERROR SchemaExport - Невозможно удалить объект "event_status", так как на него ссылается ограничение FOREIGN KEY.
Hibernate: drop table event_type
ERROR SchemaExport - HHH000389: Unsuccessful: drop table event_type
ERROR SchemaExport - Невозможно удалить объект "event_type", так как на него ссылается ограничение FOREIGN KEY.
Hibernate: drop table event_vacancy
Hibernate: drop table note
Hibernate: drop table skill
ERROR SchemaExport - HHH000389: Unsuccessful: drop table skill
ERROR SchemaExport - Невозможно удалить объект "skill", так как на него ссылается ограничение FOREIGN KEY.
Hibernate: drop table status_for_candidate
Hibernate: drop table status_for_vacancy
ERROR SchemaExport - HHH000389: Unsuccessful: drop table status_for_vacancy
ERROR SchemaExport - Невозможно удалить объект "status_for_vacancy", так как на него ссылается ограничение FOREIGN KEY.
Hibernate: drop table vacancy
ERROR SchemaExport - HHH000389: Unsuccessful: drop table vacancy
ERROR SchemaExport - Невозможно удалить объект "vacancy", так как на него ссылается ограничение FOREIGN KEY.
Hibernate: drop table vacancy_candidate
Hibernate: drop table vacancy_skill
Hibernate: drop table vacancy_status
Hibernate: create table author (id int identity not null, name varchar(255), surname varchar(255), login varchar(255) not null, password varchar(255), primary key (id))
ERROR SchemaExport - HHH000389: Unsuccessful: create table author (id int identity not null, name varchar(255), surname varchar(255), login varchar(255) not null, password varchar(255), primary key (id))
ERROR SchemaExport - В базе данных уже существует объект с именем "author".
Hibernate: create table candidate (id int identity not null, name varchar(255), surname varchar(255), creation_date datetime, phone varchar(12), cv_url varchar(100), author_id int, primary key (id))
ERROR SchemaExport - HHH000389: Unsuccessful: create table candidate (id int identity not null, name varchar(255), surname varchar(255), creation_date datetime, phone varchar(12), cv_url varchar(100), author_id int, primary key (id))
ERROR SchemaExport - В базе данных уже существует объект с именем "candidate".
Hibernate: create table candidate_skill (candidate_id int not null, skills_id int not null, primary key (candidate_id, skills_id))
Hibernate: create table candidate_status (id int identity not null, creation_date datetime, author_id int, candidate_id int, status_for_candidate_id int, primary key (id))
Hibernate: create table event (id int identity not null, creation_date datetime not null, description TEXT, event_date datetime not null, name varchar(255), author_id int, event_status_id int, event_type_id int, primary key (id))
ERROR SchemaExport - HHH000389: Unsuccessful: create table event (id int identity not null, creation_date datetime not null, description TEXT, event_date datetime not null, name varchar(255), author_id int, event_status_id int, event_type_id int, primary key (id))
ERROR SchemaExport - В базе данных уже существует объект с именем "event".
Hibernate: create table event_candidate (events_id int not null, candidates_id int not null, primary key (events_id, candidates_id))
Hibernate: create table event_status (id int identity not null, name varchar(255) not null, primary key (id))
ERROR SchemaExport - HHH000389: Unsuccessful: create table event_status (id int identity not null, name varchar(255) not null, primary key (id))
ERROR SchemaExport - В базе данных уже существует объект с именем "event_status".
Hibernate: create table event_type (id int identity not null, name varchar(255) not null, primary key (id))
ERROR SchemaExport - HHH000389: Unsuccessful: create table event_type (id int identity not null, name varchar(255) not null, primary key (id))
ERROR SchemaExport - В базе данных уже существует объект с именем "event_type".
Hibernate: create table event_vacancy (events_id int not null, vacancies_id int not null, primary key (events_id, vacancies_id))
Hibernate: create table note (id int identity not null, creation_date datetime, text TEXT not null, author_id int, candidate_id int, vacancy_id int, primary key (id))
Hibernate: create table skill (id int identity not null, name varchar(255) not null, primary key (id))
ERROR SchemaExport - HHH000389: Unsuccessful: create table skill (id int identity not null, name varchar(255) not null, primary key (id))
ERROR SchemaExport - В базе данных уже существует объект с именем "skill".
Hibernate: create table status_for_candidate (id int identity not null, name varchar(255) not null, primary key (id))
Hibernate: create table status_for_vacancy (id int identity not null, name varchar(255) not null, primary key (id))
ERROR SchemaExport - HHH000389: Unsuccessful: create table status_for_vacancy (id int identity not null, name varchar(255) not null, primary key (id))
ERROR SchemaExport - В базе данных уже существует объект с именем "status_for_vacancy".
Hibernate: create table vacancy (id int identity not null, creation_date datetime not null, description TEXT, name varchar(30) not null, author_id int, primary key (id))
ERROR SchemaExport - HHH000389: Unsuccessful: create table vacancy (id int identity not null, creation_date datetime not null, description TEXT, name varchar(30) not null, author_id int, primary key (id))
ERROR SchemaExport - В базе данных уже существует объект с именем "vacancy".
Hibernate: create table vacancy_candidate (vacancy_id int not null, candidate_id int not null, primary key (vacancy_id, candidate_id))
Hibernate: create table vacancy_skill (vacancy_id int not null, skill_id int not null, primary key (vacancy_id, skill_id))
Hibernate: create table vacancy_status (id int identity not null, creation_date datetime, author_id int, status_for_vacancy_id int, vacancy_id int, primary key (id))
Hibernate: alter table candidate add constraint FK_05002f4935184e8dbd53c777ea8 foreign key (author_id) references author
Hibernate: alter table candidate_skill add constraint FK_c5663cc54c414c94b0612d5f96c foreign key (skills_id) references skill
Hibernate: alter table candidate_skill add constraint FK_59cb93ba27dd41928c6771c5d5a foreign key (candidate_id) references candidate
Hibernate: alter table candidate_status add constraint FK_6984215820fb413eb39dfd22be1 foreign key (author_id) references author
Hibernate: alter table candidate_status add constraint FK_e85dbd64c7064bfdbbeef9b4368 foreign key (candidate_id) references candidate
Hibernate: alter table candidate_status add constraint FK_784a44e94f8f46e484eded1872c foreign key (status_for_candidate_id) references status_for_candidate
Hibernate: alter table event add constraint FK_09d336cfb68b40feae3f77ffa96 foreign key (author_id) references author
Hibernate: alter table event add constraint FK_311eae80a3a5451a8e2b1d6e434 foreign key (event_status_id) references event_status
Hibernate: alter table event add constraint FK_986e9055821c4fcfbf6ef9622c2 foreign key (event_type_id) references event_type
Hibernate: alter table event_candidate add constraint FK_0691220128eb4670ab155d5b503 foreign key (candidates_id) references candidate
Hibernate: alter table event_candidate add constraint FK_6462e163ecb64a2ead602fefc88 foreign key (events_id) references event
Hibernate: alter table event_vacancy add constraint FK_6f021945d3024aaa9e02c32f06b foreign key (vacancies_id) references vacancy
Hibernate: alter table event_vacancy add constraint FK_071e1fef728f4a8a9a90a24bab4 foreign key (events_id) references event
Hibernate: alter table note add constraint FK_b0b5a59a7ebf4dd99e2ad14f1fb foreign key (author_id) references author
Hibernate: alter table note add constraint FK_f29149788d9b4f79b9a22c2c456 foreign key (candidate_id) references candidate
Hibernate: alter table note add constraint FK_691e0ff5a54248e48b31106dbd2 foreign key (vacancy_id) references vacancy
Hibernate: alter table vacancy add constraint FK_ae885d459b2f4349b8ab8412da1 foreign key (author_id) references author
Hibernate: alter table vacancy_candidate add constraint FK_9f2264901e62465f82034f9a452 foreign key (candidate_id) references candidate
Hibernate: alter table vacancy_candidate add constraint FK_91e1f95c7480439e84286f29364 foreign key (vacancy_id) references vacancy
Hibernate: alter table vacancy_skill add constraint FK_fd280abba4e04e3abbf4a1095b4 foreign key (skill_id) references skill
Hibernate: alter table vacancy_skill add constraint FK_5c76545808be40d1a2d504aa838 foreign key (vacancy_id) references vacancy
Hibernate: alter table vacancy_status add constraint FK_144f29b0aa774611bdb2f96260b foreign key (author_id) references author
Hibernate: alter table vacancy_status add constraint FK_233da02be659464db8e989d1a7a foreign key (status_for_vacancy_id) references status_for_vacancy
Hibernate: alter table vacancy_status add constraint FK_cdfc1bd4591448cf8f47a23dbe7 foreign key (vacancy_id) references vacancy
INFO SchemaExport - HHH000230: Schema export complete
INFO HibernateTransactionManager - Using DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@7371b4ca] of Hibernate SessionFactory for HibernateTransactionManager
Собственно возникает вопрос -
1.как удалить схему по запросу используя хибер или как ее очистить(тогда второй вопрос отпадает)?
2.как создать пустую схему?
3. Как это сделать так, чтобы код не зависел от применяемой СУБД ?
|