[b]背景[/b]:[b][color=red]由于项目需要,我们在查询主信息时,可能需要通过某些明细信息来查找主信息.或者很多行转列中要用到wmsys.wm_concat这个函数.[/color][/b]
[quote][b]主,明细结构:即一对多结构
比如:订单头,订单明细[/b][/quote]
[b]实现方法[/b]:[b][color=red]我们只需要将hibernate中使用的方言改成这个新建的类,这个类并继承oracle方言,在构造函数中加上我们数据库中的函数即可(也可以是自定义函数)[/color][/b]
TmsOracle9Dialect.java
hibernate.properties
[img]http://dl.iteye.com/upload/attachment/588029/31c0dfb9-b9b3-3d8c-a1f3-7107ead4b28c.jpg[/img]
[quote][b]主,明细结构:即一对多结构
比如:订单头,订单明细[/b][/quote]
[b]实现方法[/b]:[b][color=red]我们只需要将hibernate中使用的方言改成这个新建的类,这个类并继承oracle方言,在构造函数中加上我们数据库中的函数即可(也可以是自定义函数)[/color][/b]
TmsOracle9Dialect.java
package com.vtradex.stms.server.service.dialect;
import org.hibernate.Hibernate;
import org.hibernate.dialect.Oracle9Dialect;
import org.hibernate.dialect.function.StandardSQLFunction;
/**
* @author <a href="mailto:foohsinglong@gmail.com">kevin.long</a>
* @description
*/
public class TmsOracle9Dialect extends Oracle9Dialect {
public TmsOracle9Dialect(){
super();
registerFunction("wm_concat", new StandardSQLFunction("wm_concat", Hibernate.STRING));
}
}
hibernate.properties
# $Id: hibernate.properties,v 1.13 2011/11/11 14:29:51 kevin.long Exp $
# (only applied with "dataSourceContext-hibernate.xml")
#hibernate.dialect=org.hibernate.dialect.MySQLDialect
#hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
#hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.dialect=com.vtradex.stms.server.service.dialect.TmsOracle9Dialect
#hibernate.default_schema=cjtms
hibernate.format_sql=true
hibernate.show_sql=false
hibernate.hbm2ddl.auto=none
hibernate.query.substitutions true=1, false=0
hibernate.max_fetch_depth=0
hibernate.jdbc.fetch_size=50
hibernate.jdbc.batch_size=25
hibernate.cglib.use_reflection_optimizer=true
hibernate.jdbc.use_scrollable_resultset=true
#hibernate.cache.provider_cache=org.hibernate.cache.EhCacheProvider
hibernate.cache.use_second_level_cache=false
hibernate.cache.use_query_cache=false
[img]http://dl.iteye.com/upload/attachment/588029/31c0dfb9-b9b3-3d8c-a1f3-7107ead4b28c.jpg[/img]