mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-03-03 16:29:13 +00:00
git-svn-id: https://svn.jboss.org/repos/hibernate/trunk/Hibernate3/doc@7183 1b8cb986-b30d-0410-93ca-fae66ebed9b2
445 lines
21 KiB
XML
445 lines
21 KiB
XML
<chapter id="toolsetguide" revision="2">
|
|
<title>도구셋 안내</title>
|
|
|
|
<para>
|
|
Hibernate에 대한 라운드트립 엔지니어링은 Eclipse 플러그인 세트, 명령라인 도구들, 뿐만 아니라 Ant 태스크들을 사용하여 가능하다.
|
|
</para>
|
|
|
|
<para>
|
|
<emphasis>Hibernate 도구들</emphasis>은 현재 기존 데이터베이스들에 대한 리버스 엔지니어링을 위해 Ant 태스크들 뿐만 아니라
|
|
Eclipse IDE용 플러그인들을 포함하고 있다:
|
|
</para>
|
|
|
|
<itemizedlist>
|
|
<listitem><para>
|
|
<emphasis>매핑 편집기:</emphasis> 자동 완성 기능과 구문 강조를 지원하는 Hibernate XML 매핑 파일들에 대한 편집기. 그것은 또한
|
|
통상의 XML 편집기 보다 훨씬 더 융통성 있게 만들어서 클래스 이름들과 프로퍼티/필드 이름들에 대한 의미론적 자동 완성 기능을 지원한다.
|
|
</para></listitem>
|
|
<listitem><para>
|
|
<emphasis>콘솔:</emphasis> 콘솔은 Eclipse에서 새로운 뷰이다. 당신의 콘솔 구성들에 대한 tree overview에 덧붙여, 당신은 또한
|
|
당신의 영속 클래스들과 그것들의 관계들에 대한 상호작용 뷰를 얻는다. 콘솔은 당신의 데이터베이스에 대해 HQL 질의들을 실행하고 그 결과를
|
|
Eclipse 내에서 직접 브라우징 하도록 당신에게 허용해준다.
|
|
</para></listitem>
|
|
<listitem><para>
|
|
<emphasis>개발 마법사들:</emphasis> 몇몇 마법사들이 Hibernate Eclipse 도구들에 제공된다; 당신은 Hibernate 구성
|
|
(cfg.xml) 파일들을 빠르게 생성시키는데 마법사를 사용하거나, 심지어 당신은 기존 데이터베이스 스키마를 POJO 소스 파일들과
|
|
Hibernate 매핑 파일들로 완전하게 리버스 엔지니어링할 수도 있다. 리버스 엔지니어링 마법사는 맞춤 가능한 템플릿들을 제공한다.
|
|
</para></listitem>
|
|
<listitem><para>
|
|
<emphasis>Ant 태스크들:</emphasis>
|
|
</para></listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
<para>
|
|
추가 정보는 <emphasis>Hibernate Tools</emphasis> 패키지와 그것의 문서를 참조하길 바란다.
|
|
</para>
|
|
|
|
<para>
|
|
하지만 Hibernate 메인 패키지는 통합 도구에 번들화 되어 있다(그것은 심지어 플라이 상에서 Hibernate "내에서" 사용될 수 있다):
|
|
<emphasis>SchemaExport</emphasis> 별칭은 <literal>hbm2ddl</literal>.
|
|
</para>
|
|
|
|
<sect1 id="toolsetguide-s1" revision="2">
|
|
<title>자동적인 스키마 생성</title>
|
|
|
|
<para>
|
|
DDL은 Hibernate 유틸리티에 의해 당신의 매핑 파일들로부터 생성될 수 있다. 생성된 스키마는 엔티티 테이블과 콜렉션 테이블에 대한
|
|
참조 무결성 컨스트레인트들(프라이머리 키와 foreign 키들)을 포함한다. 테이블들과 시퀀스들은 또한 페칭된 식별자 생성기들에 대해
|
|
생성된다.
|
|
</para>
|
|
|
|
<para>
|
|
DDL이 매우 벤더에 특정하므로, 이 도구를 사용할 때 당신은 <literal>hibernate.dialect</literal> 프로퍼티를 통해 한 개의 SQL
|
|
<literal>Dialect</literal>를 지정<emphasis>해야 한다</emphasis>.
|
|
</para>
|
|
|
|
<para>
|
|
먼저 생성된 스키마를 개선시키기 위해 당신의 매핑 파일들을 맞춤화 시켜라.
|
|
</para>
|
|
|
|
<sect2 id="toolsetguide-s1-2" revision="1">
|
|
<title>스키마 맞춤화 시키기</title>
|
|
|
|
<para>
|
|
많은 Hibernate 매핑 요소들은 <literal>length</literal>로 명명된 옵션 속성을 정의한다. 당신은 이 속성으로 컬럼의 길이를
|
|
설정할 수 있다.(또는 numeric/decimal 데이터 타입들, 배정도에 대해 ).
|
|
</para>
|
|
|
|
<para>
|
|
몇몇 태그들은 또한 (테이블 컬럼들에 대한 <literal>NOT NULL</literal> 컨스트레인트를 생성시키는) <literal>not-null</literal>
|
|
속성과 (테이블 컬럼들에 대한 <literal>UNIQUE</literal> 컨스트레인트를 생성시키는) <literal>unique</literal> 속성을 수용한다.
|
|
</para>
|
|
|
|
<para>
|
|
몇몇 태그들은 그 컬럼에 대한 인덱스의 이름을 지정하는 <literal>index</literal> 속성을 허용한다. <literal>unique-key</literal>
|
|
속성은 하나의 단위 키 컨스트레인트로 컬럼들을 그룹지우는데 사용될 수 있다. 현재 <literal>unique-key</literal> 속성의
|
|
지정된 값은 컨스트레인트를 명명하는데 사용되지 <emphasis>않고</emphasis>, 오직 매핑 파일 내에서 컬럼들을 그룹 지우는데
|
|
사용된다.
|
|
</para>
|
|
|
|
<para>
|
|
예제들:
|
|
</para>
|
|
|
|
<programlisting><![CDATA[<property name="foo" type="string" length="64" not-null="true"/>
|
|
|
|
<many-to-one name="bar" foreign-key="fk_foo_bar" not-null="true"/>
|
|
|
|
<element column="serial_number" type="long" not-null="true" unique="true"/>]]></programlisting>
|
|
|
|
<para>
|
|
다른 방법으로, 이들 요소들은 또한 자식 <literal><column></literal> 요소를 수용한다. 이것은 다중 컬럼 타입들에
|
|
특히 유용하다:
|
|
</para>
|
|
|
|
<programlisting><![CDATA[<property name="foo" type="string">
|
|
<column name="foo" length="64" not-null="true" sql-type="text"/>
|
|
</property>]]></programlisting>
|
|
|
|
<programlisting><![CDATA[<property name="bar" type="my.customtypes.MultiColumnType"/>
|
|
<column name="fee" not-null="true" index="bar_idx"/>
|
|
<column name="fi" not-null="true" index="bar_idx"/>
|
|
<column name="fo" not-null="true" index="bar_idx"/>
|
|
</property>]]></programlisting>
|
|
|
|
<para>
|
|
<literal>sql-type</literal> 속성은 SQL 데이터타입에 대한 Hibernate 타입의 디폴트 매핑을 오버라이드 시키는 것을
|
|
사용자에게 허용해준다.
|
|
</para>
|
|
|
|
<para>
|
|
<literal>check</literal> 속성은 check 컨스트레인트를 지정하는 것을 당신에게 허용해준다.
|
|
</para>
|
|
|
|
<programlisting><![CDATA[<property name="foo" type="integer">
|
|
<column name="foo" check="foo > 10"/>
|
|
</property>]]></programlisting>
|
|
|
|
<programlisting><![CDATA[<class name="Foo" table="foos" check="bar < 100.0">
|
|
...
|
|
<property name="bar" type="float"/>
|
|
</class>]]></programlisting>
|
|
|
|
|
|
<table frame="topbot" id="schemattributes-summary" revision="2">
|
|
<title>요약</title>
|
|
<tgroup cols="3">
|
|
<colspec colwidth="1*"/>
|
|
<colspec colwidth="1*"/>
|
|
<colspec colwidth="2.5*"/>
|
|
<thead>
|
|
<row>
|
|
<entry>속성</entry>
|
|
<entry>값들</entry>
|
|
<entry>해석</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry><literal>length</literal></entry>
|
|
<entry>number</entry>
|
|
<entry>컬럼 길이/decimal 배정도</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>not-null</literal></entry>
|
|
<entry><literal>true|false</literal></entry>
|
|
<entry>컬럼이 null이 아니어야 함을 지정한다</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>unique</literal></entry>
|
|
<entry><literal>true|false</literal></entry>
|
|
<entry>컬럼이 하나의 유일 컨스트레인트를 가져야함을 지정한다</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>index</literal></entry>
|
|
<entry><literal>index_name</literal></entry>
|
|
<entry>(다중-컬럼) 인덱스의 이름을 지정한다 </entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>unique-key</literal></entry>
|
|
<entry><literal>unique_key_name</literal></entry>
|
|
<entry>다중-컬럼 유일 컨스트레인트의 이름을 지정한다</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>foreign-key</literal></entry>
|
|
<entry><literal>foreign_key_name</literal></entry>
|
|
<entry>
|
|
하나의 연관에 대해 생성된 foreign key 컨스트레인트의 이름을 지정하고,
|
|
<one-to-one>, <many-to-one>, <key>, and <many-to-many>
|
|
매핑 요소들 상에 그것을 사용한다. <literal>inverse="true"</literal> 측들은
|
|
<literal>SchemaExport</literal>에 의해 고려되지 않을 것임을 노트하라.
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>sql-type</literal></entry>
|
|
<entry><literal>column_type</literal></entry>
|
|
<entry>
|
|
디폴트 컬럼 타입을 오버라이드 시킨다
|
|
(<literal><column></literal> 요소의 속성에만)
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>check</literal></entry>
|
|
<entry>SQL expression</entry>
|
|
<entry>
|
|
컬럼 또는 테이블에 대한 SQL check 컨스트레인트를 생성시킨다
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</table>
|
|
|
|
<para>
|
|
<literal><comment></literal> 요소는 생성된 스키마에 대한 주석들을 지정하는 것을 당신에게 허용해준다.
|
|
</para>
|
|
|
|
<programlisting><![CDATA[<class name="Customer" table="CurCust">
|
|
<comment>Current customers only</comment>
|
|
...
|
|
</class>]]></programlisting>
|
|
|
|
<programlisting><![CDATA[<property name="balance">
|
|
<column name="bal">
|
|
<comment>Balance in USD</comment>
|
|
</column>
|
|
</property>]]></programlisting>
|
|
|
|
<para>
|
|
이것은 (지원되는 경우) 생성된 DDL에서 <literal>comment on table</literal> 또는
|
|
<literal>comment on column</literal> 문장으로 귀결된다.
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
<sect2 id="toolsetguide-s1-3">
|
|
<title>도구 실행하기</title>
|
|
|
|
<para>
|
|
<literal>SchemaExport</literal> 도구는 DDL 스크립트를 표준 출력으로 기록 하고/하거나 DDL 문장들을 실행시킨다.
|
|
</para>
|
|
|
|
<para>
|
|
<literal>java -cp </literal><emphasis>hibernate_classpaths</emphasis>
|
|
<literal>org.hibernate.tool.hbm2ddl.SchemaExport</literal> <emphasis>options mapping_files</emphasis>
|
|
</para>
|
|
|
|
<table frame="topbot">
|
|
<title><literal>SchemaExport</literal> 명령 라인 옵션들</title>
|
|
<tgroup cols="2">
|
|
<colspec colwidth="1.5*"/>
|
|
<colspec colwidth="2*"/>
|
|
<thead>
|
|
<row>
|
|
<entry>옵션</entry>
|
|
<entry>설명</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry><literal>--quiet</literal></entry>
|
|
<entry>스크립트를 표준출력으로 출력하지 않는다</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>--drop</literal></entry>
|
|
<entry>오직 테이블들을 드롭시킨다</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>--text</literal></entry>
|
|
<entry>데이터베이스로 내보내기 하지 않는다</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>--output=my_schema.ddl</literal></entry>
|
|
<entry>ddl 스크립트를 파일로 출력한다</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>--config=hibernate.cfg.xml</literal></entry>
|
|
<entry>XML 파일로부터 Hibernate 구성을 읽어들인다</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>--properties=hibernate.properties</literal></entry>
|
|
<entry>파일로부터 데이터베이스 프로퍼티들을 읽어들인다</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>--format</literal></entry>
|
|
<entry>생성된 SQL을 스크립트 내에 좋게 형식지운다</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>--delimiter=x</literal></entry>
|
|
<entry>스크립트를 위한 라인 경계의 끝을 설정한다 </entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</table>
|
|
|
|
<para>
|
|
당신은 당신의 어플리케이션 내에 <literal>SchemaExport</literal>를 삽입시킬 수도 있다:
|
|
</para>
|
|
|
|
<programlisting><![CDATA[Configuration cfg = ....;
|
|
new SchemaExport(cfg).create(false, true);]]></programlisting>
|
|
|
|
</sect2>
|
|
|
|
<sect2 id="toolsetguide-s1-4">
|
|
<title>프로퍼티들</title>
|
|
|
|
<para>
|
|
데이터베이스 프로퍼티들은 다음과 같이 지정될 수 있다
|
|
</para>
|
|
|
|
<itemizedlist spacing="compact">
|
|
<listitem>
|
|
<para><literal>-D</literal><emphasis><property></emphasis>를 가진 시스템 프로퍼티로서</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para><literal>hibernate.properties</literal> 내에서</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para><literal>--properties</literal>를 가진 명명된 프로퍼티들 내에서</para>
|
|
</listitem>
|
|
</itemizedlist>
|
|
|
|
<para>
|
|
필요한 프로퍼티들은 다음과 같다:
|
|
</para>
|
|
|
|
<table frame="topbot">
|
|
<title>SchemaExport 커넥션 프로퍼티들</title>
|
|
<tgroup cols="2">
|
|
<colspec colwidth="1.5*"/>
|
|
<colspec colwidth="2*"/>
|
|
<thead>
|
|
<row>
|
|
<entry>프로퍼티 이름</entry>
|
|
<entry>설명</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry><literal>hibernate.connection.driver_class</literal></entry>
|
|
<entry>jdbc 드라이버 클래스</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>hibernate.connection.url</literal></entry>
|
|
<entry>jdbc url</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>hibernate.connection.username</literal></entry>
|
|
<entry>데이터베이스 사용자</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>hibernate.connection.password</literal></entry>
|
|
<entry>사용자 패스워드</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>hibernate.dialect</literal></entry>
|
|
<entry>dialect</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</table>
|
|
|
|
</sect2>
|
|
|
|
<sect2 id="toolsetguide-s1-5">
|
|
<title>Ant 사용하기</title>
|
|
|
|
<para>
|
|
당신은 당신의 Ant 빌드 스크립트에서 <literal>SchemaExport</literal>를 호출할 수 있다:
|
|
</para>
|
|
|
|
<programlisting><![CDATA[<target name="schemaexport">
|
|
<taskdef name="schemaexport"
|
|
classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"
|
|
classpathref="class.path"/>
|
|
|
|
<schemaexport
|
|
properties="hibernate.properties"
|
|
quiet="no"
|
|
text="no"
|
|
drop="no"
|
|
delimiter=";"
|
|
output="schema-export.sql">
|
|
<fileset dir="src">
|
|
<include name="**/*.hbm.xml"/>
|
|
</fileset>
|
|
</schemaexport>
|
|
</target>]]></programlisting>
|
|
|
|
</sect2>
|
|
|
|
<sect2 id="toolsetguide-s1-6">
|
|
<title>점증하는 스키마 업데이트들</title>
|
|
|
|
<para>
|
|
<literal>SchemaUpdate</literal> 도구는 "점증하는" 변경들을 가진 기존 스키마를 변경시킬 것이다. <literal>SchemaUpdate</literal>는
|
|
JDBC 메타데이터 API에 무겁게 의존하여서, 그것은 모든 JDBC 드라이버들에 동작하지 않을 것임을 주목하라.
|
|
</para>
|
|
|
|
<para>
|
|
<literal>java -cp </literal><emphasis>hibernate_classpaths</emphasis>
|
|
<literal>org.hibernate.tool.hbm2ddl.SchemaUpdate</literal> <emphasis>options mapping_files</emphasis>
|
|
</para>
|
|
|
|
<table frame="topbot">
|
|
<title><literal>SchemaUpdate</literal> 명령 라인 옵션들</title>
|
|
<tgroup cols="2">
|
|
<colspec colwidth="1.5*"/>
|
|
<colspec colwidth="2*"/>
|
|
<thead>
|
|
<row>
|
|
<entry>옵션</entry>
|
|
<entry>설명</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry><literal>--quiet</literal></entry>
|
|
<entry>스크립트를 표준출력으로 출력하지 않는다</entry>
|
|
</row>
|
|
<row>
|
|
<entry><literal>--properties=hibernate.properties</literal></entry>
|
|
<entry>파일로부터 데이터베이스 프로퍼티들을 읽어 들인다</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</table>
|
|
|
|
<para>
|
|
당신은 당신의 어플리케이션 내에 <literal>SchemaUpdate</literal>를 삽입시킬 수 있다:
|
|
</para>
|
|
|
|
<programlisting><![CDATA[Configuration cfg = ....;
|
|
new SchemaUpdate(cfg).execute(false);]]></programlisting>
|
|
|
|
</sect2>
|
|
|
|
<sect2 id="toolsetguide-s1-7">
|
|
<title>점증하는 스키마 업데이트들에 Ant 사용하기</title>
|
|
|
|
<para>
|
|
당신은 Ant 스크립트에서<literal>SchemaUpdate</literal>를 호출할 수 있다:
|
|
</para>
|
|
|
|
<programlisting><![CDATA[<target name="schemaupdate">
|
|
<taskdef name="schemaupdate"
|
|
classname="org.hibernate.tool.hbm2ddl.SchemaUpdateTask"
|
|
classpathref="class.path"/>
|
|
|
|
<schemaupdate
|
|
properties="hibernate.properties"
|
|
quiet="no">
|
|
<fileset dir="src">
|
|
<include name="**/*.hbm.xml"/>
|
|
</fileset>
|
|
</schemaupdate>
|
|
</target>]]></programlisting>
|
|
|
|
</sect2>
|
|
|
|
</sect1>
|
|
|
|
</chapter>
|
|
|