2013-11-15 4 views
1

잘 나는이 질문에 How do you translate Hibernate class mappings to a Spring application context?최대 절전 모드 구성

에서 거의 같은 일을 필요로하지만 난, 난, XML 매핑을 저장해야 주석을 사용하지 말아야 그래서 난 봄에 매핑을 지정하는 방법 구성?

PS 가능한 중복 미안하지만, 난 단지 주석 기반의 제안

주석

내 현재 구성 보았다 : 있는 hibernate.cfg.xml

<hibernate-configuration> 
    <session-factory> 
     <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property> 
     <property name="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521/XE</property> 
     <property name="hibernate.connection.username">username</property> 
     <property name="hibernate.connection.password">pass</property> 
     <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property> 

     <property name="show_sql">true</property> 
     <mapping class="com.foo.domain.News"></mapping> 
    </session-factory> 
</hibernate-configuration> 

applicationContext.xml sessionFactory에 콩 :

<bean id="sessionFactory" 
     class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
     <property name="dataSource" ref="dataSource" /> 
     <property name="configLocation"> 
      <value>/WEB-INF/hibernate.cfg.xml</value> 
     </property> 

     <property name="configurationClass"> 
      <value>org.hibernate.cfg.AnnotationConfiguration</value> 
     </property> 


     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.show_sql">true</prop> 
       <prop key="hibernate.dialect">${DIALECT}</prop> 
       <prop key="hibernate.connection.charSet">UTF-8</prop> 

      </props> 
     </property> 
    </bean> 

답변

1

LocalSessionFactoryBeanmappingLocations 속성을 설정 :

<property name="mappingLocations"> 
    <list> 
     <value>classpath:/path/to/mapping.hbm.xml</value> 
     ... 
    </list> 
</property> 
2

최대 절전 모드 설명서가 상당히 좋습니다.

Person.hbm.xml (which maps Person.java) 

<class name="Person" table="PERSON"> 
    <id name="id" column="PERSON_ID"> 
     <generator class="native"/> 
    </id> 
    <property name="age"/> 
    <property name="firstname"/> 
    <property name="lastname"/> 
</class> 

다음이 추가 : 당신이 좋아하는 당신에게 매핑 XML을 생성해야 Hibernate documentation

: 여기

당신이 시작하는 몇 가지 간단한 예를 최대 절전 모드 구성 파일 N

<mapping resource="Person.hbm.xml"/> 
관련 문제