Home > Database > Mysql Tutorial > Hibernate,Oracle视图中字段小数点位数使用注意

Hibernate,Oracle视图中字段小数点位数使用注意

WBOY
Release: 2016-06-07 16:57:18
Original
1485 people have browsed it

当使用Hibernate的Reverse Engineering 来自动生成Hibernate的映射文件时,会产生两个class文件,因为视图并没有主键,其中一个c

SELECT count(expscore) as count,sum(expscore) as sum,max(expscore) as max,min(expscore) as min,round

(avg(EXPSCORE)*1000)/1000 as avg,a.EXPACTID,b.teachercode,b.expname,c.classid,a.scoresubmit,a.scoreverify,c.schoolid

FROM expscore a,EXPACTIVATED b,schoolmajorclass c

where a.expactid=b.expactid and b.schclassid=c.schclassid

GROUP BY a.EXPACTID, b.teachercode, b.expname, c.classid, a.scoresubmit, a.scoreverify,c.schoolid

这是一段视图建立的SQL语句,省略了建视图语句。

当使用Hibernate的Reverse Engineering 来自动生成Hibernate的映射文件时,会产生两个class文件,因为视图并没有主键,其中一个class文件是另一个的Id,而如果要使用小数点,并控制小数点的位数,我使用的方法是这样的:

1,在建立试图时round(avg(EXPSCORE)*1000)/1000 as avg用来控制小数点的位数;

2,在生成的***.hbm.xml文件中修改属性,例如

修改为:

3,修改主键id的class文件,将自动生成声明为Long的变量,,改成Double型。

4,同时不要忘了在Hibernate.cfg.xml中添加这个新的*.hbm.xml配置文件。

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template