Menu

  • Home
  • Work
    • Cloud
      • Virtualization
      • IaaS
      • PaaS
    • Java
    • Go
    • C
    • C++
    • JavaScript
    • PHP
    • Python
    • Architecture
    • Others
      • Assembly
      • Ruby
      • Perl
      • Lua
      • Rust
      • XML
      • Network
      • IoT
      • GIS
      • Algorithm
      • AI
      • Math
      • RE
      • Graphic
    • OS
      • Linux
      • Windows
      • Mac OS X
    • BigData
    • Database
      • MySQL
      • Oracle
    • Mobile
      • Android
      • IOS
    • Web
      • HTML
      • CSS
  • Life
    • Cooking
    • Travel
    • Gardening
  • Gallery
  • Video
  • Music
  • Essay
  • Home
  • Work
    • Cloud
      • Virtualization
      • IaaS
      • PaaS
    • Java
    • Go
    • C
    • C++
    • JavaScript
    • PHP
    • Python
    • Architecture
    • Others
      • Assembly
      • Ruby
      • Perl
      • Lua
      • Rust
      • XML
      • Network
      • IoT
      • GIS
      • Algorithm
      • AI
      • Math
      • RE
      • Graphic
    • OS
      • Linux
      • Windows
      • Mac OS X
    • BigData
    • Database
      • MySQL
      • Oracle
    • Mobile
      • Android
      • IOS
    • Web
      • HTML
      • CSS
  • Life
    • Cooking
    • Travel
    • Gardening
  • Gallery
  • Video
  • Music
  • Essay

Tag Archives: Hibernate

Java

Spring配置:集成Hibernate、JacksonJSON、AspectJ等框架

本文提及的该套配置文件,覆盖了JavaEE项目开发的最常见需求,包括:依赖注入、事务控制、AOP、任务调度、缓存、MVC框架等方面的内容。 容易改变的配置项独立到属性文件中:
applicationConfig.properties
Shell
1
2
3
4
5
6
hibernateDialect=org.hibernate.dialect.MySQL5Dialect
#启用了log4jdbc支持
jdbcDriver=net.sf.log4jdbc.DriverSpy
jdbcDriverUrl=jdbc:log4jdbc:mysql://192.168.0.201:3306/initpemsdb1.1.1
jdbcUserName=root
jdbcPassword=root
Spring配置文件部分:
applicationContext.xml
XHTML
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
<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xmlns:cache="http://www.springframework.org/schema/cache"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/task  http://www.springframework.org/schema/task/spring-task-3.0.xsd
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
    ">
    <!-- 定义属性,在后面的配置中可以使用#{appCfg.xxx}引用 -->
    <util:properties id="appCfg" location="classpath:applicationConfig.properties" />
    <!-- 包扫描配置 -->
    <context:component-scan base-package="cc.gmem.demo">
        <!-- 去除Java Config类 -->
        <context:exclude-filter type="annotation" expression="org.springframework.context.annotation.Configuration" />
        <!-- 去除Spring MVC类 -->
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
        <!-- 匹配AspectJ Pattern的类被去除 -->
        <context:exclude-filter type="aspectj" expression="cc.gmem.demo.aop.web.*" />
    </context:component-scan>
    <!-- 启用注解支持 -->
    <context:annotation-config />
    <!-- 支持@Configurable注解 -->
    <context:spring-configured />
    <!--  启用注解方式的事务:基于AspectJ织入 -->
    <tx:annotation-driven transaction-manager="txManager" mode="aspectj" />
    <!--  启用注解方式的缓存配置:基于AspectJ织入 -->
    <cache:annotation-driven cache-manager="cacheManager" mode="aspectj" />
    <!--  启用注解方式的任务执行(例如@Async):基于AspectJ织入 -->
    <task:annotation-driven executor="taskExecutor" mode="aspectj" />
    
    <!--  任务调度器配置,pool-size为线程池大小,限制了同时最多被调度的任务 -->
    <task:scheduler pool-size="100" id="scheduler" />
    <!-- 任务计划列表,支持固定频率、固定延迟、Cron表达式等 -->
    <task:scheduled-tasks scheduler="scheduler">
        <task:scheduled fixed-rate="120000" method="run" ref="hibernateStatisticsMonitor" />
    </task:scheduled-tasks>
    <!-- 任务执行器,用于异步执行任务 -->
    <task:executor id="taskExecutor" keep-alive="3600" pool-size="10-100" queue-capacity="10000" rejection-policy="CALLER_RUNS" />
    <!-- 引入其它Spring配置文件 -->
    <import resource="report-and-etl.xml" />  
    <!-- Hibernate配置  -->
    <bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
        <property name="alias" value="connectionPool" />
        <property name="driver" value="#{appCfg.jdbcDriver}" />
        <property name="driverUrl" value="#{appCfg.jdbcDriverUrl}" />
        <property name="user" value="#{appCfg.jdbcUserName}" />
        <property name="password" value="#{appCfg.jdbcPassword}" />
        <property name="statistics" value="10s" />
        <property name="minimumConnectionCount" value="10" />
        <property name="maximumConnectionCount" value="100" />
        <property name="simultaneousBuildThrottle" value="10" />
        <property name="maximumActiveTime" value="3600000" />
    </bean>
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" autowire="byName" />
    <bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor" lazy-init="true" />
    <bean id="sessionFactory" p:dataSource-ref="dataSource" class="cc.gmem.demo.hibernate.AnnotationSessionFactoryBean" depends-on="appCfg" >
        <property name="packagesToScan">
            <list>
                <value>cc.gmem.demo.**.domain</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <value>
                hibernate.dialect=#{appCfg.hibernateDialect}
                hibernate.jdbc.batch_size=30
                hibernate.show_sql=false
                hibernate.format_sql=true
                hibernate.generate_statistics=true
                hibernate.transaction.factory_class=org.hibernate.transaction.JDBCTransactionFactory
                hibernate.current_session_context_class=org.springframework.orm.hibernate3.SpringSessionContext
                hibernate.query.factory_class=org.hibernate.hql.ast.ASTQueryTranslatorFactory
                hibernate.hbm2ddl.auto=update
                #启用二级缓存
                hibernate.cache.use_second_level_cache=true
                hibernate.cache.use_query_cache=true
                hibernate.cache.region.factory_class=org.hibernate.cache.SingletonEhCacheRegionFactory
            </value>
        </property>
    </bean>
    <!-- Spring缓存配置 -->
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
        <property name="cacheManager" ref="ehcache" />
    </bean>
    <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation">
            <value>classpath:ehcache.xml</value>
        </property>
        <property name="shared" value="true" />
    </bean>
    <bean id="hibernateStatisticsMonitor" class="cc.gmem.demo.hibernate.HibernateStatisticsMonitor" />
    <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory" />
    <!-- Velocity引擎配置 -->
    <bean id="velocityEngine" class="org.apache.velocity.app.VelocityEngine">
        <constructor-arg type="java.util.Properties">
            <value>
                <![CDATA[
                #{T(org.apache.velocity.runtime.RuntimeConstants).RUNTIME_LOG_LOGSYSTEM_CLASS}=org.apache.velocity.runtime.log.Log4JLogChute
                runtime.log.logsystem.log4j.logger=velocityLogger
                #{T(org.apache.velocity.runtime.RuntimeConstants).INPUT_ENCODING}=UTF-8
                #{T(org.apache.velocity.runtime.RuntimeConstants).OUTPUT_ENCODING}=UTF-8
                #{T(org.apache.velocity.runtime.RuntimeConstants).VM_PERM_ALLOW_INLINE}=true
                #{T(org.apache.velocity.runtime.RuntimeConstants).RESOURCE_LOADER}=class
                #{T(org.apache.velocity.runtime.RuntimeConstants).PARSER_POOL_SIZE}=100
                class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
                ]]>
            </value>
        </constructor-arg>
    </bean>
    <!--国际化支持-->
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
         <property name="basenames">
             <list>
                 <value>classpath:message.gmemdemo</value>
             </list>
         </property>
         <property name="defaultEncoding" value="UTF-8" />
         <property name="cacheSeconds" value="5" />
    </bean>
    <!--Jackson JSON -->
    <bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper" autowire="byType" />
    <!-- Spring类型转换服务,特别是用于时间日期格式转换 -->
    <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
        <property name="converters">
            <set>
               <bean class="net.greenmemory.spring.converter.DateTimeConvertor">
                    <constructor-arg>
                       <array>
                            <value>yyyy-MM-dd</value>
                           <value>yyyy-MM-dd HH:mm:ss</value>
                           <value>yyyy-MM-dd HH:mm:ss.SSS</value>
                       </array>
                   </constructor-arg>
                </bean>
            </set>
       </property>
       <property name="formatters">
          <set>
              <bean class="org.springframework.format.datetime.DateFormatter">
                  <constructor-arg>
                      <value>yyyy-MM-dd</value>
                  </constructor-arg>
               </bean>
           </set>
       </property>
       <property name="formatterRegistrars">
           <set>
           </set>
       </property>
    </bean>
</beans>
Spring MVC配置文件部分: ehcache配置部分: Web.xml配置(使用了Spring的JavaConfig): Java Config类: Maven依赖包列表: Mave… 阅读全文
10 years ago
0
Java

基于JavaConfig方式的Spring+Hibernate集成

JavaConfig类
包含Spring、Hibernate、事务管理等功能的样例
BeanDefinitionRegistrar.java
Java
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
package sparknet.wnet.saic.intf.spring;
 
import java.io.IOException;
import java.util.Properties;
 
import javax.inject.Inject;
import javax.sql.DataSource;
 
import net.greenmemory.breeze.persist.OracleProxoolDataSource;
import net.greenmemory.commons.db.QueryRunner;
import net.greenmemory.commons.lang.NumberUtils;
import net.greenmemory.spring.core.io.ClassPathResource;
 
import org.hibernate.SessionFactory;
import org.springframework.aop.framework.autoproxy.InfrastructureAdvisorAutoProxyCreator;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.FilterType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.hibernate3.HibernateTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.AnnotationTransactionAttributeSource;
import org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor;
import org.springframework.transaction.interceptor.TransactionInterceptor;
 
import cc.gmem.tools.hibernatetools.spring.Hibernate3LocalSessionFactoryBean;
 
@Configuration
@ComponentScan (
        basePackages = { "cc.gmem.saic", "cc.gmem.intf" },
        excludeFilters = { @Filter ( type = FilterType.ANNOTATION, value = Configuration.class ) } )
@EnableAspectJAutoProxy
public class BeanDefinitionRegistrar
{
 
    @Inject
    private ApplicationContext applicationContext;
 
    @Bean ( name = "cfg" )
    public Properties getAppConfig()
    {
        Properties props = new Properties();
        try
        {
            props.load( new ClassPathResource( "wsi.properties" ).getInputStream() );
        }
        catch ( IOException e )
        {
            throw new BeanInitializationException( e.getMessage(), e );
        }
        return props;
    }
 
    @Bean ( name = "dataSource" )
    public DataSource getDataSource()
    {
        OracleProxoolDataSource dataSource = new OracleProxoolDataSource();
        dataSource.setAlias( getAppConfig().getProperty( "jdbc.alias" ) );
        dataSource.setDriver( getAppConfig().getProperty( "jdbc.driverClass" ) );
        dataSource.setDriverUrl( getAppConfig().getProperty( "jdbc.url" ) );
        dataSource.setUser( getAppConfig().getProperty( "jdbc.user" ) );
        dataSource.setPassword( getAppConfig().getProperty( "jdbc.password" ) );
        dataSource.setMinimumConnectionCount( NumberUtils.toInt( getAppConfig().getProperty( "jdbc.minimumConnectionCount" ), 10 ) );
        dataSource.setMaximumConnectionCount( NumberUtils.toInt( getAppConfig().getProperty( "jdbc.maximumConnectionCount" ), 100 ) );
        dataSource.setSimultaneousBuildThrottle( NumberUtils.toInt( getAppConfig().getProperty( "jdbc.simultaneousBuildThrottle" ), 50 ) );
        dataSource.setMaximumActiveTime( NumberUtils.toInt( getAppConfig().getProperty( "jdbc.maximumActiveTime" ), 1200000 ) );
        dataSource.setEncrypted( false );
        dataSource.init();
        return dataSource;
    }
 
    @Bean ( name = "sessionFactory" )
    public SessionFactory getSessionFactory() throws Exception
    {
        Hibernate3LocalSessionFactoryBean bean = new Hibernate3LocalSessionFactoryBean();
        bean.setApplicationContext( applicationContext );
        bean.setDataSource( getDataSource() );
        bean.setMappingResources( new String[] { "wnetJhInterface.hbm.xml" } );
        bean.setAutoRegister( true );
        Properties hibernateProperties = new Properties();
        hibernateProperties.setProperty( "hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect" );
        hibernateProperties.setProperty( "hibernate.jdbc.batch_size", "100" );
        hibernateProperties.setProperty( "hibernate.default_entity_mode", "dom4j" );
        hibernateProperties.setProperty( "hibernate.transaction.factory_class", "org.hibernate.transaction.JDBCTransactionFactory" );
        hibernateProperties.setProperty( "hibernate.current_session_context_class", "org.springframework.orm.hibernate3.SpringSessionContext" );
        bean.setHibernateProperties( hibernateProperties );
        bean.afterPropertiesSet();
        return bean.getObject();
    }
 
    @Bean ( name = "txManager" )
    public PlatformTransactionManager getTransactionManager() throws Exception
    {
        HibernateTransactionManager txMgr = new HibernateTransactionManager();
        txMgr.setSessionFactory( getSessionFactory() );
        return txMgr;
    }
 
    @Bean ( name = "jdbcTemplate" )
    public JdbcTemplate getJdbcTemplate()
    {
        return new JdbcTemplate( getDataSource() );
    }
 
    @Bean ( name = "queryRunner" )
    public QueryRunner getQueryRunner()
    {
        return new QueryRunner( getDataSource() );
    }
 
    @Bean
    public AnnotationTransactionAttributeSource transactionAttributeSource()
    {
        return new AnnotationTransactionAttributeSource();
    }
 
    @Bean
    public TransactionInterceptor transactionInterceptor() throws Exception
    {
        return new TransactionInterceptor( getTransactionManager(), transactionAttributeSource() );
    }
 
    @Bean
    public TransactionAttributeSourceAdvisor internalTransactionAdvisor() throws Exception
    {
        return new TransactionAttributeSourceAdvisor( transactionInterceptor() );
    }
 
    @Bean
    public InfrastructureAdvisorAutoProxyCreator internalAutoProxyCreator()
    {
        return new InfrastructureAdvisorAutoProxyCreator();
    }
}
初始化Spring ApplicationContext的代码
Java
1
2
ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanDefinitionRegistrar.class);
DataSource ds= ctx.getBean(DataSource.class);
阅读全文
10 years ago
0
Java

Hibernate知识集锦

重要概念
get和load

在Hibernate 3.6.x中:

get会返回实际的对象实例,如果不存在则返回null,session.get(Superclass.class,id)与session.get(Concreteclass,id)的返回值完全一致。…

阅读全文
10 years ago
0
Java

Hibernate基于注解的配置样例

实体类上的常用注解
Java
1
2
3
4
5
6
7
8
9
10
11
12
13
@Entity ( name = "ChristmasTree" )
@Table ( name = "T_CRISMS_TREE" )
//给自动生成的表添加注释
@org.hibernate.annotations.Table ( appliesTo = "T_CRISMS_TREE", comment = "圣诞树" )
@Cacheable  //JPA注解,表示该类型的实体支持缓存
//启用二级缓存时有意义,指定Hibernate缓存策略、存放区域
@Cache ( usage = CacheConcurrencyStrategy.READ_WRITE, region = "entityCache" )
public class ChristmasTree
{
    //集合属性的缓存策略必须单独配置
    @Cache ( usage = CacheConcurrencyStrategy.READ_WRITE, region = "entityCache" )
    private List branches;
}

使用注解方式进行对象-数据库映射时,应当以JPA注解为主,仅Hibernate特有的功能则使用其私有的注解类。

简单主键和简单属性映射
Java
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
//简单的主键映射
@Id  //该注解指明此实体的标识符属性,对应了关系型数据库的主键
@Column ( name = "ID", columnDefinition = "int(11) comment '主键'" )
private Integer id;
 
//UUID方式的主键生成器配置,其它任何自定义的主键生成器可以依样扩展
@Id
@Column ( name = "ID", columnDefinition = "varchar(36) comment '主键,36位UUID'" )
@GeneratedValue ( generator = "uuid" )
@GenericGenerator ( name = "uuid", strategy = "org.hibernate.id.UUIDGenerator" )
private String            id;
 
//可以指定普通属性的延迟加载
@Basic ( fetch = FetchType.EAGER, optional = true )
@Column ( name = "BUILD_COST", columnDefinition = "decimal(10,2) comment '建造费用'" )
private BigDecimal buildCost;
 
//时间映射
//只能用于java.util.Date或者java.util.Calendar,用于表示日期、时间或者时间戳
@Temporal ( TemporalType.TIMESTAMP )
@Column ( name = "BUILD_TIME", columnDefinition = "datetime comment '建造时间'" )
private Date buildTime;
 
//大字段映射
@Lob
@Column ( name = "REMARK", columnDefinition = "longtext comment '圣诞树备注信息'" )
private String remark;
 
//枚举类型映射
@Enumerated ( EnumType.ORDINAL )
//根据枚举元素的声明顺序,从0开始
@Column ( name = "STATUS", columnDefinition = "tinyint comment '状态'" )
private Status status;
 
 
//乐观并发控制用列
@Version
@Column ( name = "VERSION" )
public Integer version;
复合主键映射
嵌入式(embeddable)对象映射
关联映射
继承映射
其它注解
阅读全文
12 years ago
0
Java

Hibernate基于XML的配置文件样例

Hibernate 3.0配置文件
XHTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="cpdb">
  <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
  <property name="hibernate.connection.password">CASTOR</property>
  <property name="hibernate.connection.url">jdbc:oracle:thin:@RD-DB-5.sparknet.com.cn:1522:CPDB</property>
  <property name="hibernate.connection.username">CASTOR</property>
  <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
  <property name="hibernate.jdbc.batch_size">20</property>
  <property name="hibernate.show_sql">true</property>
  <property name="hibernate.format_sql">true</property>
  <property name="hibernate.generate_statistics">true</property>
  <property name="hibernate.current_session_context_class">thread</property>
</session-factory>
</hibernate-configuration>
XRM配置文件样例

XRM是Hibernate3里面的一个试验性功能,用于在数据库和XML文件之间进行映射

XHTML
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="sparknet.traing.hxm.model">
    <class entity-name="Corp" node="corp" table="T_CORP">
        <comment>
            <![CDATA[
                Corporation basic information
            ]]>
        </comment>
        <!-- 复合主键的映射 -->
        <composite-id name="id" node="-">
            <key-property name="org" node="org" type="long">
                <column name="ORG" sql-type="NUMBER(8)">
                    <comment>database Code</comment>
                </column>
            </key-property>
            <key-property name="id" node="id" type="long">
                <column name="ID" sql-type="NUMBER(8)">
                    <comment>corporation identifier</comment>
                </column>
            </key-property>
            <key-property name="seqId" node="seq-id" type="long">
                <column name="SEQ_ID" sql-type="NUMBER(8)">
                    <comment>changing sequence</comment>
                </column>
            </key-property>
            <generator class="foreign">
                <param name="property">corpOther</param>
            </generator>
        </composite-id>
        <!-- 普通属性的映射 -->
        <property name="corpName" node="corp-name" type="string" unique="true" unique-key="UK_CORP_NAME">
            <column name="CORP_NAME" sql-type="VARCHAR(64)">
                <comment>corporation name</comment>
            </column>
        </property>
        <property name="regCapi" node="reg-capi" type="currency">
            <column name="REG_CAPI" sql-type="NUMBER(14,2)">
                <comment>registered capital</comment>
            </column>
        </property>
        <property name="startDate" node="start-date" type="fmt_date">
            <column name="START_DATE" sql-type="DATE">
                <comment> corporation start date</comment>
            </column>
        </property>
        <property name="startTime" node="start-time" type="fmt_time">
            <column name="START_TIME" sql-type="DATE">
                <comment> corporation start time</comment>
            </column>
        </property>
        <!-- 组件映射 -->
        <component name="address" node="addr" lazy="true">
            <property name="street" node="street" type="string">
                <column name="STREET" sql-type="VARCHAR2(128)">
                    <comment>address of street</comment>
                </column>
            </property>
            <property name="building" node="building" type="string">
                <column name="BUILDING" sql-type="VARCHAR2(128)">
                    <comment>building</comment>
                </column>
            </property>
            <property name="zipCode" node="zip-code" type="int">
                <column name="ZIP" sql-type="NUMBER(6)">
                    <comment>zip code</comment>
                </column>
            </property>
        </component>
        <!-- 共享主键的一对一关联,目前这个版本,会导致当前Class的主键不能映射到XML中? -->
        <one-to-one name="corpOther" entity-name="AdvancedCorpInfo" node="corp-other-info" constrained="true" cascade="all" />
        <!-- 多对一映射 -->
        <many-to-one name="city" entity-name="City" embed-xml="true" node="city-code" cascade="all">
            <column name="CITY_ID" sql-type="NUMBER(8)">
                <comment>address of city</comment>
            </column>
        </many-to-one>
        <many-to-one name="gongShangOrg" node="belong-dist-org" entity-name="GongShangOrg" cascade="all">
            <column name="GS_ORG" sql-type="NUMBER(8)"></column>
            <column name="GS_ID" sql-type="NUMBER(8)"></column>
            <column name="GS_SEQ_ID" sql-type="NUMBER(8)"></column>
        </many-to-one>
        <!-- 基于连接表的一对多双向关联,One端-->
        <list name="stocks" embed-xml="true" node="stocks-of-corp" cascade="all,delete-orphan" batch-size="20" table="T_M_CORP_STOCK">
            <key not-null="true" foreign-key="FK_CORP_STOCK">
                <column name="CORP_ORG" sql-type="NUMBER(8)" />
                <column name="CORP_ID" sql-type="NUMBER(8)" />
                <column name="CORP_SEQ_ID" sql-type="NUMBER(8)" />
            </key>
            <list-index>
                <column name="ORD">
                    <comment>list index</comment>
                </column>
            </list-index>
            <many-to-many unique="true" entity-name="Stock" node="stock" embed-xml="true">
                <column name="STOCK_ORG" sql-type="NUMBER(8)" />
                <column name="STOCK_ID" sql-type="NUMBER(8)" />
                <column name="STOCK_SEQ_ID" sql-type="NUMBER(8)" />
            </many-to-many>
        </list>
        <!-- 基于外键的一对多关联,One端 -->
        <set name="oldStocks">
            <key>
                <column name="CORP_ORG" sql-type="NUMBER(8)" />
                <column name="CORP_ID" sql-type="NUMBER(8)" />
                <column name="CORP_SEQ_ID" sql-type="NUMBER(8)" />
            </key>
            <one-to-many entity-name="stock"/>
        </set>
        <property name="timestamp" node="timestamp" type="fmt_date_time">
            <column name="STATE_DATE">
                <comment>Version column</comment>
            </column>
        </property>
    </class>
    <class entity-name="Stock" node="Stock" table="T_STOCK">
        <composite-id name="id" node="identifier">
            <key-property name="org" node="org" type="long">
                <column name="ORG" sql-type="NUMBER(8)">
                    <comment>database Code</comment>
                </column>
            </key-property>
            <key-property name="id" node="id" type="long">
                <column name="ID" sql-type="NUMBER(8)">
                    <comment>stock identifier</comment>
                </column>
            </key-property>
            <key-property name="seqId" node="seq-id" type="long">
                <column name="SEQ_ID" sql-type="NUMBER(8)">
                    <comment>changing sequence</comment>
                </column>
            </key-property>
            <generator class="assigned" />
        </composite-id>
        <property name="stockName" node="stock-name" not-null="true" type="string">
            <column name="NAME" sql-type="VARCHAR2(64)">
                <comment>stock's name</comment>
            </column>
        </property>
        <property name="stockType" node="stock-type" type="string">
            <column name="STOCK_TYPE" sql-type="VARCHAR2(64)">
                <comment>type of a stock</comment>
            </column>
        </property>
        <property name="stockRegCapi" node="stock-registered-capital" type="double">
            <column name="STOCK_REG_CAPI" sql-type="NUMBER(12,2)">
                <comment>registered capital of a stock</comment>
            </column>
        </property>
        <property name="stockActualCapi" node="stock-actual-capital" type="double">
            <column name="STOCK_ACTUAL_CAPI" sql-type="NUMBER(12,2)">
                <comment>actual capital of a stock</comment>
            </column>
        </property>
        <property name="capiType" node="captial-type" type="string">
            <column name="CAPI_TYPE" sql-type="VARCHAR2(64)">
                <comment>capi type of a stock</comment>
            </column>
        </property>
        <!-- 基于连接表的一对多双向关联,Many端 -->
        <join table="T_M_CORP_STOCK" inverse="true" optional="true">
            <key not-null="true" foreign-key="FK_CORP_STOCK">
                <column name="STOCK_ORG" sql-type="NUMBER(8)" />
                <column name="STOCK_ID" sql-type="NUMBER(8)" />
                <column name="STOCK_SEQ_ID" sql-type="NUMBER(8)" />
            </key>
            <!-- 注意:在本Sample中,如果下行embed-xml设置为true则导致循环引用,XML处理出错 -->
            <many-to-one name="corp" embed-xml="false" entity-name="Corp" node="corp-ref">
                <column name="CORP_ORG" sql-type="NUMBER(8)" />
                <column name="CORP_ID" sql-type="NUMBER(8)" />
                <column name="CORP_SEQ_ID" sql-type="NUMBER(8)" />
            </many-to-one>
        </join>
    </class>
    <class entity-name="GongShangOrg" node="org" table="T_DICT_ORG">
        <composite-id name="id" node="-">
            <key-property name="org" node="org" type="long">
                <column name="ORG" sql-type="NUMBER(8)">
                    <comment>database Code</comment>
                </column>
            </key-property>
            <key-property name="id" node="id" type="long">
                <column name="ID" sql-type="NUMBER(8)">
                    <comment>gong shang org identifier</comment>
                </column>
            </key-property>
            <key-property name="seqId" node="seq-id" type="long">
                <column name="SEQ_ID" sql-type="NUMBER(8)">
                    <comment>changing sequence</comment>
                </column>
            </key-property>
            <generator class="assigned" />
        </composite-id>
        <property name="orgName" node="org-name" type="string">
            <column name="NAME" sql-type="VARCHAR2(64)">
                <comment>city name</comment>
            </column>
        </property>
    </class>
    <class entity-name="AdvancedCorpInfo" node="adv-corp-info" table="T_CORP_OTHER">
        <composite-id name="id" node="-">
            <key-property name="org" node="org" type="long">
                <column name="ORG" sql-type="NUMBER(8)">
                    <comment>database Code</comment>
                </column>
            </key-property>
            <key-property name="id" node="id" type="long">
                <column name="ID" sql-type="NUMBER(8)">
                    <comment>corporation identifier</comment>
                </column>
            </key-property>
            <key-property name="seqId" node="seq-id" type="long">
                <column name="SEQ_ID" sql-type="NUMBER(8)">
                    <comment>changing sequence</comment>
                </column>
            </key-property>
            <generator class="assigned" />
        </composite-id>
        <property name="webSite" node="web-site" type="string">
            <column name="WEB_URL" sql-type="VARCHAR2(128)">
                <comment>web site url</comment>
            </column>
        </property>
        <property name="citySign" node="city-or-village" type="boolean">
            <column name="CITY_SIGN" sql-type="NUMBER(1)">
                <comment>city village flag</comment>
            </column>
        </property>
    </class>
    <class entity-name="City" node="City" table="T_DICT_CITY">
        <comment>
            <![CDATA[
                City dictionary
            ]]>
        </comment>
        <!-- 简单主键映射 -->
        <id name="cityId" node="-" type="long" >
            <column name="CITY_ID" sql-type="NUMBER(8)">
                <comment>city identifier</comment>
            </column>
            <generator class="sequence">
                <param name="sequence">SEQ_HXM</param>
            </generator>
        </id>
        <property name="cityName" node="-" type="string">
            <column name="NAME" sql-type="VARCHAR2(64)">
                <comment>city name</comment>
            </column>
        </property>
        <property name="cityCode" node="." type="int">
            <column name="CODE" sql-type="NUMBER(4)">
                <comment>city code</comment>
            </column>
        </property>
    </class>
</hibernate-mapping>
阅读全文
13 years ago
0

Recent Posts

  • Terraform快速参考
  • 草缸2021
  • 编写Kubernetes风格的APIServer
  • 记录一次KeyDB缓慢的定位过程
  • eBPF学习笔记
ABOUT ME

汪震 | Alex Wong

江苏淮安人,现居北京。目前供职于腾讯云,专注容器方向。

GitHub:gmemcc

Git:git.gmem.cc

Email:gmemjunk@gmem.cc@me.com

ABOUT GMEM

绿色记忆是我的个人网站,域名gmem.cc中G是Green的简写,MEM是Memory的简写,CC则是我的小天使彩彩名字的简写。

我在这里记录自己的工作与生活,同时和大家分享一些编程方面的知识。

GMEM HISTORY
v2.00:微风
v1.03:单车旅行
v1.02:夏日版
v1.01:未完成
v0.10:彩虹天堂
v0.01:阳光海岸
MIRROR INFO
Meta
  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
Recent Posts
  • Terraform快速参考
    简介 Terraform用于实现基础设施即代码(infrastructure as code)—— 通过代码( ...
  • 草缸2021
    经过四个多月的努力,我的小小荷兰景到达极致了状态。

  • 编写Kubernetes风格的APIServer
    背景 前段时间接到一个需求做一个工具,工具将在K8S中运行。需求很适合用控制器模式实现,很自然的就基于kube ...
  • 记录一次KeyDB缓慢的定位过程
    环境说明 运行环境 这个问题出现在一套搭建在虚拟机上的Kubernetes 1.18集群上。集群有三个节点: ...
  • eBPF学习笔记
    简介 BPF,即Berkeley Packet Filter,是一个古老的网络封包过滤机制。它允许从用户空间注 ...
  • IPVS模式下ClusterIP泄露宿主机端口的问题
    问题 在一个启用了IPVS模式kube-proxy的K8S集群中,运行着一个Docker Registry服务 ...
  • 念爷爷
      今天是爷爷的头七,十二月七日、阴历十月廿三中午,老人家与世长辞。   九月初,回家看望刚动完手术的爸爸,发

  • 6 杨梅坑

  • liuhuashan
    深圳人才公园的网红景点 —— 流花山

  • 1 2020年10月拈花湾

  • 内核缺陷触发的NodePort服务63秒延迟问题
    现象 我们有一个新创建的TKE 1.3.0集群,使用基于Galaxy + Flannel(VXLAN模式)的容 ...
  • Galaxy学习笔记
    简介 Galaxy是TKEStack的一个网络组件,支持为TKE集群提供Overlay/Underlay容器网 ...
  • Istio中的透明代理问题
    为何需要透明代理 Istio的Sidecar作为一个网络代理,它拦截入站、出站的网络流量。拦截入站流量后,会使 ...
  • Cilium学习笔记
    简介 Cilium Cilium是在Docker/K8S之类的容器管理平台下,透明的为应用程序服务提供安全网 ...
  • 彩彩 2020年6月黄崖关

  • 总部远眺 2020年5月深圳

  • 绚丽之花 寻味顺德

  • tuanbolake 团泊湖野餐

TOPLINKS
  • Zitahli's blue 91 people like this
  • 梦中的婚礼 64 people like this
  • 汪静好 61 people like this
  • 那年我一岁 36 people like this
  • 为了爱 28 people like this
  • 小绿彩 26 people like this
  • 彩虹姐姐的笑脸 24 people like this
  • 杨梅坑 6 people like this
  • 亚龙湾之旅 1 people like this
  • 汪昌博 people like this
  • 2013年11月香山 10 people like this
  • 2013年7月秦皇岛 6 people like this
  • 2013年6月蓟县盘山 5 people like this
  • 2013年2月梅花山 2 people like this
  • 2013年淮阴自贡迎春灯会 3 people like this
  • 2012年镇江金山游 1 people like this
  • 2012年徽杭古道 9 people like this
  • 2011年清明节后扬州行 1 people like this
  • 2008年十一云龙公园 5 people like this
  • 2008年之秋忆 7 people like this
  • 老照片 13 people like this
  • 火一样的六月 16 people like this
  • 发黄的相片 3 people like this
  • Cesium学习笔记 88 people like this
  • IntelliJ IDEA知识集锦 59 people like this
  • 基于Kurento搭建WebRTC服务器 38 people like this
  • PhoneGap学习笔记 32 people like this
  • NaCl学习笔记 32 people like this
  • 使用Oracle Java Mission Control监控JVM运行状态 29 people like this
  • 基于Calico的CNI 27 people like this
  • Ceph学习笔记 26 people like this
  • Three.js学习笔记 24 people like this
Tag Cloud
ActiveMQ AspectJ CDT Ceph Chrome CNI Command Cordova Coroutine CXF Cygwin DNS Docker eBPF Eclipse ExtJS F7 FAQ Groovy Hibernate HTTP IntelliJ IO编程 IPVS JacksonJSON JMS JSON JVM K8S kernel LB libvirt Linux知识 Linux编程 LOG Maven MinGW Mock Monitoring Multimedia MVC MySQL netfs Netty Nginx NIO Node.js NoSQL Oracle PDT PHP Redis RPC Scheduler ServiceMesh SNMP Spring SSL svn Tomcat TSDB Ubuntu WebGL WebRTC WebService WebSocket wxWidgets XDebug XML XPath XRM ZooKeeper 亚龙湾 单元测试 学习笔记 实时处理 并发编程 彩姐 性能剖析 性能调优 文本处理 新特性 架构模式 系统编程 网络编程 视频监控 设计模式 远程调试 配置文件 齐塔莉
Recent Comments
  • 黄豆豆 on Ginkgo学习笔记
  • cloud on OpenStack学习笔记
  • 5dragoncon on Cilium学习笔记
  • Archeb on 重温iptables
  • C/C++编程:WebSocketpp(Linux + Clion + boostAsio) – 源码巴士 on 基于C/C++的WebSocket库
  • jerbin on eBPF学习笔记
  • point on Istio中的透明代理问题
  • G on Istio中的透明代理问题
  • 绿色记忆:Go语言单元测试和仿冒 on Ginkgo学习笔记
  • point on Istio中的透明代理问题
  • 【Maven】maven插件开发实战 – IT汇 on Maven插件开发
  • chenlx on eBPF学习笔记
  • Alex on eBPF学习笔记
  • CFC4N on eBPF学习笔记
  • 李运田 on 念爷爷
  • yongman on 记录一次KeyDB缓慢的定位过程
  • Alex on Istio中的透明代理问题
  • will on Istio中的透明代理问题
  • will on Istio中的透明代理问题
  • haolipeng on 基于本地gRPC的Go插件系统
  • 吴杰 on 基于C/C++的WebSocket库
  • 绿色记忆:Nginx知识集锦 on Apache HTTP Server知识集锦
  • NotMeBug on AspectJ编程学习笔记
©2005-2023 Gmem.cc | Powered by WordPress