<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="anyframe.sample.model.bidirection.Country"
table="COUNTRY" lazy="true" schema="PUBLIC">
<id name="countryCode" type="string">
<column name="COUNTRY_CODE" length="12" />
<generator class="assigned" />
</id>
<property name="countryId" type="string">
<column name="COUNTRY_ID" length="2" not-null="true" />
</property>
<property name="countryName" type="string">
<column name="COUNTRY_NAME" length="50" not-null="true" />
</property>
<!-- 중략 -->
</class>
</hibernate-mapping>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
| DB schema의 이름 | |||
| DB catalog의 이름 | |||
| 매핑 클래스가 있는 패키지 이름 | |||
| Class, Class내 정의된 Collection에 대한 기본 lazy 로딩 속성 |
<hibernate-mapping schema=".." package=“…”>
<class name="Foo" table=“TBL_FOO">
…
</class>
</hibernate-mapping>
| 매핑 클래스의 이름(hibernate-mapping 태그에서 package를 정의하지 않았다면 클래스의 패키지명도 함께 정의한다.) | |||
| DB 테이블 명 | |||
| true일 경우 객체가 필요한 순간에 로딩한다. | <hibernate-mapping> 내의 default-lazy 속성값 |
||
| DB schema의 이름(상위 태그에서 명시를 안했을 경우 정의 할 수 있다.) | <hibernate-mapping> 내의 schema 속성값 |
<class name="Foo" table="TBL_FOO">
<id name="id" column="ID" type="int">
<generator class="assigned"/>
</id>
<property name="name" column="NAME" type="string"/>
</class>
<class name="Foo" table="TBL_FOO">
<composite-id>
<key-property name="username“
column="USERNAME" />
<key-property name="organizationId"
column="ORGANIZATION_ID" />
</composite-id>
…중략
</class>
| DB의 primary key칼럼과 매핑 될 attribute 이름 | |||
| DB 테이블의 key칼럼 이름 | name 속성의 값 | ||
| attribute 타입(Java 객체의 type가 아니라 Hibernate의 매핑타입) |
<property name="countryId" type="string"> <column name="COUNTRY_ID" length="2" not-null="true" /> </property>
| 매핑 될 attribute 이름 | |||
| attribute 타입(Java 객체의 type가 아니라 Hibernate의 매핑타입) |
| DB 테이블의 컬럼 이름 | |||
| 컴럼의 값의 길이 | |||
| 컬럼값이 필수인지 아닌지 설정 (true or false) |
<property name="countryId" type="string"> <column name="COUNTRY_ID" length="2" not-null="true" /> </property>
public class JavaDataType {
private int id;
private int intType;
private long longType;
private short shortType;
private float floatType;
private double doubleType;
private java.math.BigDecimal bigDecimalType;
private String stringType;
private char charType;
private byte byteType;
private boolean booleanType;
private boolean yesNoType;
private boolean trueFalseType;
<!-- 중략 -->
<property name="intType" column="INT_TYPE" type="int"/> <property name="longType" column="LONG_TYPE" type="long"/> <property name="shortType" column="SHORT_TYPE" type="short"/> <property name="floatType" column="FLOAT_TYPE" type="float"/> <property name="doubleType" column="DOUBLE_TYPE" type="double"/> <property name="bigDecimalType" column="BIGDECIMAL_TYPE" type="big_decimal"/> <property name="charType" column="CHAR_TYPE" type="character"/> <property name="stringType" column="STRING_TYPE" type="string"/> <property name="byteType" column="BYTE_TYPE" type="byte"/> <property name="booleanType" column="BOOLEAN_TYPE" type="boolean"/> <property name="yesNoType" column="YES_NO_TYPE" type="yes_no"/> <property name="trueFalseType" column="TRUE_FALSE_TYPE" type="true_false"/>
public class TimeDateType {
private java.sql.Date dateType;
private java.sql.Time timeType;
private java.sql.Timestamp timestampType;
private java.util.Calendar calendarType;
private java.util.Calendar calendarDateType;
<!-- 중략 -->
<property name="dateType" column="DATE_TYPE" type="date"/> <property name="timeType" column="TIME_TYPE" type="time"/> <property name="timestampType" column="TIMESTAMP_TYPE" type="timestamp"/> <property name="calendarType" column="CALENDAR_TYPE" type="calendar"/> <property name="calendarDateType" column="CALENDAR_DATE_TYPE" type="calendar_date"/>
public class BlobDataType {
private String fileName;
private java.math.BigDecimal fileSize;
private byte[] fileContentByte;
private Blob fileContentBlob;
public class ClobDataType {
private String title;
private String contentString;
private Clob contentClob;
<property name="fileName" column="FILE_NAME" type="text"/> <property name="fileSize" column="FILE_SIZE" type="big_decimal"/> <property name="fileContentByte" column="FILE_CONTENT_BYTE" type="binary" /> <property name="fileContentBlob" column="FILE_CONTENT_BLOB" type="blob"/>
<property name="title" column="TITLE" type="text"/> <property name="contentString" column="CONTENT_STRING" type="text"/> <property name="contentClob" column="CONTENT_CLOB" type="clob"/>
<class name="anyframe.sample.model.unidirection.generator.CountryWithIdentity" table="COUNTRY_IDENTITY" lazy="true" schema="PUBLIC"> <id name="countryCode" column="COUNTRY_CODE" type="int"> <generator class="identity" /> </id> <!-- 중략 -->
public void testAddCountryWithIdentityGenerator() throws Exception {
CountryWithIdentity country1 = new CountryWithIdentity();
country1.setCountryId("KR");
country1.setCountryName("Korea");
Integer countryCode = (Integer) session.save(country1);
<!-- 중략 -->
}
<class name="anyframe.sample.model.unidirection.generator.CountryWithSequence" table="COUNTRY_SEQ" lazy="true" schema="PUBLIC"> <id name="countryCode" type="int"> <column name="COUNTRY_CODE" length="12" /> <generator class="sequence"> <param name="sequence">COUNTRY_ID_SEQ</param> </generator> </id> <!-- 중략 -->
public void testAddCountryWithSequenceGenerator() throws Exception {
CountryWithSequence country1 = new CountryWithSequence();
country1.setCountryId("KR");
country1.setCountryName("Korea");
Integer countryCode = (Integer) session.save(country1);
<!-- 중략 -->
}
<class name="anyframe.sample.model.unidirection.generator.CountryWithHilo" table="COUNTRY_HILO" lazy="true" schema="PUBLIC"> <id name="countryCode" column="COUNTRY_CODE" type="int"> <generator class="hilo"> <param name="table">ID_MANAGEMENT</param> <param name="column">NEXT_VALUE</param> <param name="max_lo">2</param> </generator> </id>
select NEXT_VALUE from ID_MANAGEMENT update ID_MANAGEMENT set NEXT_VALUE = 1 where NEXT_VALUE = 0
public void testAddCountryWithHiloGenerator() throws Exception {
CountryWithSeqHilo country1 = new CountryWithSeqHilo();
country1.setCountryId("KR");
country1.setCountryName("Korea");
Integer countryCode1 = (Integer) session.save(country1);
<!-- 중략 -->
CountryWithSeqHilo country2 = new CountryWithSeqHilo();
country2.setCountryId("JP");
country2.setCountryName("Japan");
Integer countryCode2 = (Integer) session.save(country2);
<!--중략 -->
CountryWithSeqHilo country3 = new CountryWithSeqHilo();
country3.setCountryId("US");
country3.setCountryName("U.S.A");
Integer countryCode3 = (Integer) session.save(country3);
}
<class name="anyframe.sample.model.unidirection.generator.CountryWithSeqHilo" table="COUNTRY_SEQHILO" lazy="true" schema="PUBLIC"> <id name="countryCode" column="COUNTRY_CODE" type="int"> <generator class="seqhilo"> <param name="sequence">COUNTRY_ID_SEQ</param> <param name="max_lo">2</param> </generator> </id> <!-- 중략 -->
call next value for COUNTRY_ID_SEQ
public void testAddCountryWithSeqHiloGenerator() throws Exception {
CountryWithSeqHilo country1 = new CountryWithSeqHilo();
country1.setCountryId("KR");
country1.setCountryName("Korea");
Integer countryCode1 = (Integer) session.save(country1);
<!-- 중략 -->
CountryWithSeqHilo country2 = new CountryWithSeqHilo();
country2.setCountryId("JP");
country2.setCountryName("Japan");
Integer countryCode2 = (Integer) session.save(country2);
<!-- 중략 -->
CountryWithSeqHilo country3 = new CountryWithSeqHilo();
country3.setCountryId("US");
country3.setCountryName("U.S.A");
Integer countryCode3 = (Integer) session.save(country3);
<!-- 중략 -->
}
<class name="anyframe.sample.model.unidirection.generator.CountryWithIncrement" table="COUNTRY_INCREMENT" lazy="true" schema="PUBLIC"> <id name="countryCode" type="int"> <column name="COUNTRY_CODE" length="12" /> <generator class="increment" /> </id> <!-- 중략 -->
select max(COUNTRY_CODE) from COUNTRY_INCREMENT
public void testAddCountryWithIncrementGenerator() throws Exception {
CountryWithIncrement country1 = new CountryWithIncrement();
country1.setCountryId("KR");
country1.setCountryName("Korea");
Integer countryCode1 = (Integer) session.save(country1);
<!-- 중략 -->
CountryWithIncrement country2 = new CountryWithIncrement();
country2.setCountryId("JP");
country2.setCountryName("Japan");
Integer countryCode2 = (Integer) session.save(country2);
<!-- 중략 -->
CountryWithIncrement country3 = new CountryWithIncrement();
country3.setCountryId("US");
country3.setCountryName("U.S.A");
Integer countryCode3 = (Integer) session.save(country3);
}
<class name="anyframe.sample.model.unidirection.generator.CountryWithUUID" table="COUNTRY_UUID" lazy="true" schema="PUBLIC"> <id name="countryCode" column="COUNTRY_CODE" type="string"> <generator class="uuid"> <param name="separator">#</param> </generator> </id> <!-- 중략 -->
public void testAddCountryWithUUIDGenerator() throws Exception {
CountryWithUUID country1 = new CountryWithUUID();
country1.setCountryId("KR");
country1.setCountryName("대한민국");
String countryCode = (String) session.save(country1);
}
insert into PUBLIC.COUNTRY_UUID (COUNTRY_ID, COUNTRY_NAME, COUNTRY_CODE) values ('KR', '대한민국',
'c687b6dc#1c894fc4#011c#894fc5ef#0001')
<id name="categoryNo" type="string"> <column name="CATEGORY_NO" length="16" /> <generator class="assigned" /> </id>
category.setCategoryNo(idGenerationService.getNextStringId()); <!-- 중략 --> session.save(category);