---
title: "Hibernate 支持wm_concat等函数"
author: "foohsinglong"
date: "2011-11-14T16:31:35Z"
tags: []
categories: ["编程语言"]
slug: "hibernate-wm-concat"
draft: false
lastmod: "2011-11-14T16:38:15Z"
id: 1258416
url: "https://foohsinglong.iteye.com/blog/1258416"
---

\[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 \[code="java"]package com.vtradex.stms.server.service.dialect; import org.hibernate.Hibernate; import org.hibernate.dialect.Oracle9Dialect; import org.hibernate.dialect.function.StandardSQLFunction; /\** * @author [kevin.long](mailto:foohsinglong@gmail.com) * @description \*/ public class TmsOracle9Dialect extends Oracle9Dialect { public TmsOracle9Dialect(){ super(); registerFunction("wm\_concat", new StandardSQLFunction("wm\_concat", Hibernate.STRING)); } }\[/code] hibernate.properties \[code="java"]# $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\[/code] \[img]http://dl.iteye.com/upload/attachment/588029/31c0dfb9-b9b3-3d8c-a1f3-7107ead4b28c.jpg\[/img]