리버스 엔지니어링 확인 제약 조건 및 인덱스가 Hibernate?
-
14-11-2019 - |
문제
큰 레거시, SQL Server 데이터베이스에서 리버스 엔지니어링 Hibernate 매핑으로 작업 해 왔습니다.데이터베이스는 체크 제약 조건 (테이블 당 여러) 및 인덱스의 광범위한 사용을 사용하며, 이들이 DBA 문제라고 주장하는 동안 우리는 Hibernate 매핑에서 보존해야합니다.
Eclipse의 Hibernate Tools를 사용하면 테이블을 .hbm.xml 파일로 성공적으로 리버스 엔지니어링 할 수 있습니다.그러나 검사 제약 조건이나 인덱스 중 어느 것도 존재하지 않습니다.체크 제약 조건 및 인덱스를 모두 맵핑에 직접 추가 할 수 있음을 알고 있습니다.
<class name="package.Tablename"
table="TABLENAME"
schema="dbo"
catalog="MyDB"
check="START_DATE < END_DATE"> <!-- here -->
...
<property name="endDate" type="timestamp" index="IDX_END_DATE"> <!-- here -->
<column name="END_DATE" />
</property>
...
</class>
.
우리는 수백 가지 테이블과 수천 개의 색인 / 체크 제약 조건을 가지고 있으므로 리버스 엔지니어링 된 매핑에 손으로 이들을 추가하는 것은 실제로 실제로 실제로 실제로 사용할 수 없습니다.
우리를 위해 이들을 침을 뱉어내는 최대 절전 도구를 얻을 수 있습니까?그렇다면 어떻게?그렇지 않은 경우 누구 든지이 작업을 수행 할 다른 도구를 추천 할 수 있습니까?
해결책
It's not possible to do this out of the box with Hibernate Tools; however, it is possible to add DDL to your mappings inside of <database-object>
elements. In order to reverse engineer this information, you'll have to write a custom utility class that is invoked via a custom template.
Since a boatload of <database-object>
s didn't provide the level of abstraction and general user-friendlyness that my employer wanted, we opted not to take this approach and modeled our database in a different manner.