锁定老帖子 主题:hibernate在新项目上应用的弊端
该帖已经被评为隐藏帖
|
|
---|---|
作者 | 正文 |
发表时间:2011-04-26
hibernate不适合业务逻辑复杂的系统
固然hibernate可以使用原生的SQL,可以访问存储过程。但是,一旦使用原生的SQL或者是访问存储过程,再使用hibernate不是脱裤子放屁,多此一举么? 我们做的一个系统,业务逻辑复杂,都是使用ibatis或者是jdbctemplate访问存储过程来实现,举个例子如下: CREATE PROCEDURE P_ts_kc_zwh @qxdh char(2) As set nocount on update syk set tszwh = '' where qxdh=@qxdh declare @kddhi char(4), @id int, @spc int, @wpc int, @ksrs int, @spci int, @wpci int declare @zrsi int, @wrsi int, @mpcrs int, @mrs1 int, @mrs2 int, @mrs3 int, @kddh char(4) declare @pci int, @szh char(10), @wzh char(10), @jdh char(10), @rsi int, @bxdh char(4) declare @zwhi int, @bzwh int, @wjdh bigint, @kchi int set @kddhi = '' set @wpci = 0 set @spci = 0 declare cur_kwk cursor for select id,kddh,spc,wpc,ksrs from tskwk where left(kddh,2)=@qxdh order by kddh,spc,wpc,bxdh,szh open cur_kwk fetch next from cur_kwk into @id,@kddh,@spc,@wpc,@ksrs while @@fetch_status = 0 begin if @kddh <> @kddhi or @spc <> @wpci begin set @kddhi = @kddh set @spci = @spc set @zrsi = 0 set @wrsi = 0 select @mpcrs=ksrs1+ksrs2+ksrs3+ksrs4 from tskdk where kddh=@kddh end set @wpci = @wpc update tskwk set bzwh = @wrsi+1 where id=@id set @zrsi = @zrsi + @ksrs set @wrsi = @zrsi - (@wpci-@spci)*@mpcrs fetch next from cur_kwk into @id,@kddh,@spc,@wpc,@ksrs end close cur_kwk deallocate cur_kwk declare cur_kwk cursor for select kddh,spc,ksrs,bzwh,szh,wzh from tskwk where left(kddh,2)=@qxdh and szh<>'' order by kddh,spc,wpc,szh open cur_kwk fetch next from cur_kwk into @kddh,@spc,@ksrs,@bzwh,@szh,@wzh while @@fetch_status = 0 begin select @mpcrs=ksrs1+ksrs2+ksrs3+ksrs4,@mrs1=ksrs1,@mrs2=ksrs1+ksrs2,@mrs3=ksrs1+ksrs2+ksrs3 from tskdk where kddh=@kddh set @pci = @spc set @rsi = @bzwh set @zwhi = case when @bzwh<=@mrs1 then @bzwh when @bzwh<=@mrs2 then @bzwh-@mrs1 when @bzwh<=@mrs3 then @bzwh-@mrs2 else @bzwh-@mrs3 end declare cur_syk cursor for select jdh from syk where jdh>=@szh and jdh<=@wzh and tszwh='' and jf_ts='1' order by bjh,jdh open cur_syk fetch next from cur_syk into @jdh while @@fetch_status = 0 begin if @rsi > @mpcrs begin set @pci = @pci + 1 set @rsi = 1 set @zwhi = 1 end set @kchi = case when @rsi<=@mrs1 then 1 when @rsi<=@mrs2 then 2 when @rsi<=@mrs3 then 3 else 4 end update syk set tszwh=@kddh+right('0'+cast(@kchi as varchar(2)),2)+ right('0'+cast(@pci as varchar(2)),2) + right('0'+cast(@zwhi as varchar(2)),2) where jdh = @jdh set @zwhi = @zwhi + 1 set @rsi = @rsi + 1 if @rsi=@mrs1+1 or @rsi=@mrs2+1 or @rsi=@mrs3+1 set @zwhi = 1 set @ksrs = @ksrs-1 if @ksrs = 0 break fetch next from cur_syk into @jdh end close cur_syk deallocate cur_syk fetch next from cur_kwk into @kddh,@spc,@ksrs,@bzwh,@szh,@wzh end close cur_kwk deallocate cur_kwk declare cur_kwk cursor for select kddh,spc,bxdh,ksrs,bzwh from tskwk where left(kddh,2)=@qxdh and szh=space(10) order by kddh,spc,wpc,bxdh open cur_kwk fetch next from cur_kwk into @kddh,@spc,@bxdh,@ksrs,@bzwh while @@fetch_status = 0 begin select @mpcrs=ksrs1+ksrs2+ksrs3+ksrs4,@mrs1=ksrs1,@mrs2=ksrs1+ksrs2,@mrs3=ksrs1+ksrs2+ksrs3 from tskdk where kddh=@kddh set @pci = @spc set @rsi = @bzwh set @zwhi = case when @rsi<=@mrs1 then @rsi when @rsi<=@mrs2 then @rsi-@mrs1 when @rsi<=@mrs3 then @rsi-@mrs2 else @rsi-@mrs3 end declare cur_syk cursor for select jdh from syk where bxdh=@bxdh and tszwh='' and jf_ts='1' order by bjh,jdh open cur_syk fetch next from cur_syk into @jdh while @@fetch_status = 0 --and @ksrs>0 begin if @rsi > @mpcrs begin set @pci = @pci + 1 set @rsi = 1 set @zwhi = 1 end set @kchi = case when @rsi<=@mrs1 then 1 when @rsi<=@mrs2 then 2 when @rsi<=@mrs3 then 3 else 4 end update syk set tszwh=@kddh+right('0'+cast(@kchi as varchar(2)),2)+ right('0'+cast(@pci as varchar(2)),2) + right('0'+cast(@zwhi as varchar(2)),2) where jdh = @jdh set @zwhi = @zwhi + 1 set @rsi = @rsi + 1 if @rsi=@mrs1+1 or @rsi=@mrs2+1 or @rsi=@mrs3+1 set @zwhi = 1 set @ksrs = @ksrs-1 if @ksrs = 0 break fetch next from cur_syk into @jdh end close cur_syk deallocate cur_syk fetch next from cur_kwk into @kddh,@spc,@bxdh,@ksrs,@bzwh end close cur_kwk deallocate cur_kwk set nocount off GO 请问这样的存储过程如何用Hql实现? |
|
返回顶楼 | |
发表时间:2011-04-26
我有个同学在orcale工作,他说:hibernate的流行,是因为现在程序员的数据库基本功大部分太差了
|
|
返回顶楼 | |
发表时间:2011-04-26
在一些地理信息的字段映射时,HEBERNATE就不给力了
|
|
返回顶楼 | |
发表时间:2011-04-26
楼主像是在抱怨啊
不习惯用就不要用 用自己擅长的就好了 |
|
返回顶楼 | |
发表时间:2011-04-26
吸取各自的精华才是取胜之道~!
|
|
返回顶楼 | |
发表时间:2011-04-26
最后修改:2011-04-26
buydzyj 写道 我有个同学在orcale工作,他说:hibernate的流行,是因为现在程序员的数据库基本功大部分太差了
深表赞同!很多连左右关联能干什么都不知道。都写了几年代码了。 很怀疑他以前的系统能否查出正确的记录数。 |
|
返回顶楼 | |
发表时间:2011-04-26
作为一个只会jdbc和hibernate的人来说,压力很大
|
|
返回顶楼 | |
发表时间:2011-04-26
hibernate 用起来确实有难度
|
|
返回顶楼 | |
发表时间:2011-04-26
查询前X位最XX的,复杂如报表的数据展示查询需求,用Hibernate的hql简直是自虐。
一般的数据查询,Hibernate的作用就是一个自动类型转换器而已。很多时候把Hibernate当成mapping工具使用,不见得比其他类似的framework优越多少。当业务逻缉处理没有达到复杂并且大量的程度到可以抽象出来形成可重用的单元,用Hibernate往往还不如sql开个事务来处理方便直接。 一旦发现业务逻缉都累积在一个connection事务方法里面,再来审视是否需要重构吧~~~~ 清晰的业务逻缉处理层次,带来代码结构的清爽,是Hibernate诸如ORM工具给我们最大的好处。当然代价是有的... 某人说,ORM重点在O,不在M... |
|
返回顶楼 | |
发表时间:2011-04-27
buydzyj 写道 hibernate不适合业务逻辑复杂的系统
固然hibernate可以使用原生的SQL,可以访问存储过程。但是,一旦使用原生的SQL或者是访问存储过程,再使用hibernate不是脱裤子放屁,多此一举么? 我们做的一个系统,业务逻辑复杂,都是使用ibatis或者是jdbctemplate访问存储过程来实现,举个例子如下: CREATE PROCEDURE P_ts_kc_zwh @qxdh char(2) As set nocount on update syk set tszwh = '' where qxdh=@qxdh declare @kddhi char(4), @id int, @spc int, @wpc int, @ksrs int, @spci int, @wpci int declare @zrsi int, @wrsi int, @mpcrs int, @mrs1 int, @mrs2 int, @mrs3 int, @kddh char(4) declare @pci int, @szh char(10), @wzh char(10), @jdh char(10), @rsi int, @bxdh char(4) declare @zwhi int, @bzwh int, @wjdh bigint, @kchi int set @kddhi = '' set @wpci = 0 set @spci = 0 declare cur_kwk cursor for select id,kddh,spc,wpc,ksrs from tskwk where left(kddh,2)=@qxdh order by kddh,spc,wpc,bxdh,szh open cur_kwk fetch next from cur_kwk into @id,@kddh,@spc,@wpc,@ksrs while @@fetch_status = 0 begin if @kddh <> @kddhi or @spc <> @wpci begin set @kddhi = @kddh set @spci = @spc set @zrsi = 0 set @wrsi = 0 select @mpcrs=ksrs1+ksrs2+ksrs3+ksrs4 from tskdk where kddh=@kddh end set @wpci = @wpc update tskwk set bzwh = @wrsi+1 where id=@id set @zrsi = @zrsi + @ksrs set @wrsi = @zrsi - (@wpci-@spci)*@mpcrs fetch next from cur_kwk into @id,@kddh,@spc,@wpc,@ksrs end close cur_kwk deallocate cur_kwk declare cur_kwk cursor for select kddh,spc,ksrs,bzwh,szh,wzh from tskwk where left(kddh,2)=@qxdh and szh<>'' order by kddh,spc,wpc,szh open cur_kwk fetch next from cur_kwk into @kddh,@spc,@ksrs,@bzwh,@szh,@wzh while @@fetch_status = 0 begin select @mpcrs=ksrs1+ksrs2+ksrs3+ksrs4,@mrs1=ksrs1,@mrs2=ksrs1+ksrs2,@mrs3=ksrs1+ksrs2+ksrs3 from tskdk where kddh=@kddh set @pci = @spc set @rsi = @bzwh set @zwhi = case when @bzwh<=@mrs1 then @bzwh when @bzwh<=@mrs2 then @bzwh-@mrs1 when @bzwh<=@mrs3 then @bzwh-@mrs2 else @bzwh-@mrs3 end declare cur_syk cursor for select jdh from syk where jdh>=@szh and jdh<=@wzh and tszwh='' and jf_ts='1' order by bjh,jdh open cur_syk fetch next from cur_syk into @jdh while @@fetch_status = 0 begin if @rsi > @mpcrs begin set @pci = @pci + 1 set @rsi = 1 set @zwhi = 1 end set @kchi = case when @rsi<=@mrs1 then 1 when @rsi<=@mrs2 then 2 when @rsi<=@mrs3 then 3 else 4 end update syk set tszwh=@kddh+right('0'+cast(@kchi as varchar(2)),2)+ right('0'+cast(@pci as varchar(2)),2) + right('0'+cast(@zwhi as varchar(2)),2) where jdh = @jdh set @zwhi = @zwhi + 1 set @rsi = @rsi + 1 if @rsi=@mrs1+1 or @rsi=@mrs2+1 or @rsi=@mrs3+1 set @zwhi = 1 set @ksrs = @ksrs-1 if @ksrs = 0 break fetch next from cur_syk into @jdh end close cur_syk deallocate cur_syk fetch next from cur_kwk into @kddh,@spc,@ksrs,@bzwh,@szh,@wzh end close cur_kwk deallocate cur_kwk declare cur_kwk cursor for select kddh,spc,bxdh,ksrs,bzwh from tskwk where left(kddh,2)=@qxdh and szh=space(10) order by kddh,spc,wpc,bxdh open cur_kwk fetch next from cur_kwk into @kddh,@spc,@bxdh,@ksrs,@bzwh while @@fetch_status = 0 begin select @mpcrs=ksrs1+ksrs2+ksrs3+ksrs4,@mrs1=ksrs1,@mrs2=ksrs1+ksrs2,@mrs3=ksrs1+ksrs2+ksrs3 from tskdk where kddh=@kddh set @pci = @spc set @rsi = @bzwh set @zwhi = case when @rsi<=@mrs1 then @rsi when @rsi<=@mrs2 then @rsi-@mrs1 when @rsi<=@mrs3 then @rsi-@mrs2 else @rsi-@mrs3 end declare cur_syk cursor for select jdh from syk where bxdh=@bxdh and tszwh='' and jf_ts='1' order by bjh,jdh open cur_syk fetch next from cur_syk into @jdh while @@fetch_status = 0 --and @ksrs>0 begin if @rsi > @mpcrs begin set @pci = @pci + 1 set @rsi = 1 set @zwhi = 1 end set @kchi = case when @rsi<=@mrs1 then 1 when @rsi<=@mrs2 then 2 when @rsi<=@mrs3 then 3 else 4 end update syk set tszwh=@kddh+right('0'+cast(@kchi as varchar(2)),2)+ right('0'+cast(@pci as varchar(2)),2) + right('0'+cast(@zwhi as varchar(2)),2) where jdh = @jdh set @zwhi = @zwhi + 1 set @rsi = @rsi + 1 if @rsi=@mrs1+1 or @rsi=@mrs2+1 or @rsi=@mrs3+1 set @zwhi = 1 set @ksrs = @ksrs-1 if @ksrs = 0 break fetch next from cur_syk into @jdh end close cur_syk deallocate cur_syk fetch next from cur_kwk into @kddh,@spc,@bxdh,@ksrs,@bzwh end close cur_kwk deallocate cur_kwk set nocount off GO 请问这样的存储过程如何用Hql实现? 我很想知道你用jdbc或者ibatis写这个存储过程咋写?别告诉我用CallStatement |
|
返回顶楼 | |