- 浏览: 116883 次
- 性别:
- 来自: 武汉
文章分类
最新评论
-
Odysseus_110:
terryang 写道lz加上时间也不太合适,刷新太快的话还是 ...
$.getJSON 缓存 -
ll.james:
5楼的,真管用通知公告模块A.通知公告的类型没有实现控制B.通 ...
$.getJSON 缓存 -
zranye:
这样虽然能启动,但是会出现乱码
resin 无法启动 com.caucho.config.LineConfigException: -
酒杯中的大海:
学习了!!!~
struts 文件上传 乱码 -
酒杯中的大海:
牛逼,膜拜~
struts 文件上传 乱码
java pojo类和hibernate映射文件分别为:
/** * SysRepeaterMng entity. * * @author MyEclipse Persistence Tools */ public class SysRepeaterMng implements java.io.Serializable { // Fields /** * */ private static final long serialVersionUID = -7028035445611074921L; private Long id; private String reptSid; private String reptNam; private String reptIp; private Date joinTime; private String memo; private Long state; private String password; private Long isserver; private Long publishmode; //private String stateCN;//服务器状态 中文名称 //private String isserverCN;//服务器类型 中文名称 //private String publishmodeCN;//服务器发布方式 中文名称 private Set itemPublishFails; // Constructors /** * @return the itemPublishFails */ public Set getItemPublishFails() { return itemPublishFails; } /** * @param itemPublishFails the itemPublishFails to set */ public void setItemPublishFails(Set itemPublishFails) { this.itemPublishFails = itemPublishFails; } /** default constructor */ public SysRepeaterMng() { } /** minimal constructor */ public SysRepeaterMng(Long id, String reptSid, String reptNam, String reptIp, Date joinTime, Long state,Set itemPublishFails) { this.id = id; this.reptSid = reptSid; this.reptNam = reptNam; this.reptIp = reptIp; this.joinTime = joinTime; this.state = state; this.itemPublishFails = itemPublishFails; } /** full constructor */ public SysRepeaterMng(Long id, String reptSid, String reptNam, String reptIp, Date joinTime, String memo, Long state, String password,Set itemPublishFails) { this.id = id; this.reptSid = reptSid; this.reptNam = reptNam; this.reptIp = reptIp; this.joinTime = joinTime; this.memo = memo; this.state = state; this.password = password; this.itemPublishFails = itemPublishFails; } // Property accessors public Long getId() { return this.id; } public void setId(Long id) { this.id = id; } public String getReptSid() { return this.reptSid; } public void setReptSid(String reptSid) { this.reptSid = reptSid; } public String getReptNam() { return this.reptNam; } public void setReptNam(String reptNam) { this.reptNam = reptNam; } public String getReptIp() { return this.reptIp; } public void setReptIp(String reptIp) { this.reptIp = reptIp; } public Date getJoinTime() { return this.joinTime; } public void setJoinTime(Date joinTime) { this.joinTime = joinTime; } public String getMemo() { return this.memo; } public void setMemo(String memo) { this.memo = memo; } public Long getState() { return this.state; } public void setState(Long state) { this.state = state; } public String getPassword() { return this.password; } public void setPassword(String password) { this.password = password; } /** * @return the isserver */ public Long getIsserver() { return isserver; } /** * @param isserver * the isserver to set */ public void setIsserver(Long isserver) { this.isserver = isserver; } /** * @return the publishmode */ public Long getPublishmode() { return publishmode; } /** * @param publishmode * the publishmode to set */ public void setPublishmode(Long publishmode) { this.publishmode = publishmode; } }
<?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"> <!-- Mapping file autogenerated by MyEclipse Persistence Tools --> <hibernate-mapping> <class name="com.SysRepeaterMng" table="SYS_REPEATER_MNG" schema="ZHENGJIANG"> <id name="id" type="java.lang.Long"> <column name="ID" precision="10" scale="0" /> <generator class="sequence"> <param name="sequence">SYSREPEATERMNG_sequence</param> </generator> </id> <property name="reptSid" type="java.lang.String"> <column name="REPT_SID" length="10" not-null="true" unique="true" /> </property> <property name="reptNam" type="java.lang.String"> <column name="REPT_NAM" length="50" not-null="true" /> </property> <property name="reptIp" type="java.lang.String"> <column name="REPT_IP" length="50" not-null="true" /> </property> <property name="joinTime" type="java.util.Date"> <column name="JOIN_TIME" length="7" not-null="true" /> </property> <property name="memo" type="java.lang.String"> <column name="MEMO" length="256" /> </property> <property name="state" type="java.lang.Long"> <column name="STATE" precision="1" scale="0" not-null="true" /> </property> <property name="password" type="java.lang.String"> <column name="PASSWORD" length="20" /> </property> <property name="isserver" type="java.lang.Long"> <column name="IS_SERVER" precision="1" scale="0" not-null="true" /> </property> <property name="publishmode" type="java.lang.Long"> <column name="PUBLISH_MODE" precision="1" scale="0" not-null="true" /> </property> <set name="itemPublishFails" table="ITEM_PUBLISH_FAIL" inverse="true" lazy="false" cascade="all"> <key column="REPT_SID"></key> <one-to-many class="com.ItemPublishFail"/> </set> </class> </hibernate-mapping>
/** * ItemPublishFail entity. * * @author MyEclipse Persistence Tools */ public class ItemPublishFail implements java.io.Serializable { // Fields /** * */ private static final long serialVersionUID = -3002520851890289401L; private Long itemId; private String channelNam; private Integer channelTpid; private String mediaType; private Integer codeRate; private Integer publishMode; private Integer pubPrv; private Date failTime; private String channelUrl; private String channelPic; private String channelDesc; private String keyWord; private SysRepeaterMng sysRepeaterMng; // Constructors /** default constructor */ public ItemPublishFail() { } /** full constructor */ public ItemPublishFail(String channelNam, Integer channelTpid, String mediaType, Integer codeRate, Integer publishMode, Integer pubPrv, Date failTime, String channelUrl, String channelPic, String channelDesc, String keyWord, SysRepeaterMng sysRepeaterMng) { this.channelNam = channelNam; this.channelTpid = channelTpid; this.mediaType = mediaType; this.codeRate = codeRate; this.publishMode = publishMode; this.pubPrv = pubPrv; this.failTime = failTime; this.channelUrl = channelUrl; this.channelPic = channelPic; this.channelDesc = channelDesc; this.keyWord = keyWord; this.sysRepeaterMng = sysRepeaterMng; } // Property accessors public Long getItemId() { return this.itemId; } public void setItemId(Long itemId) { this.itemId = itemId; } public String getChannelNam() { return this.channelNam; } public void setChannelNam(String channelNam) { this.channelNam = channelNam; } public Integer getChannelTpid() { return this.channelTpid; } public void setChannelTpid(Integer channelTpid) { this.channelTpid = channelTpid; } public String getMediaType() { return this.mediaType; } public void setMediaType(String mediaType) { this.mediaType = mediaType; } public Integer getCodeRate() { return this.codeRate; } public void setCodeRate(Integer codeRate) { this.codeRate = codeRate; } public Integer getPublishMode() { return this.publishMode; } public void setPublishMode(Integer publishMode) { this.publishMode = publishMode; } public Integer getPubPrv() { return this.pubPrv; } public void setPubPrv(Integer pubPrv) { this.pubPrv = pubPrv; } public Date getFailTime() { return this.failTime; } public void setFailTime(Date failTime) { this.failTime = failTime; } public String getChannelUrl() { return this.channelUrl; } public void setChannelUrl(String channelUrl) { this.channelUrl = channelUrl; } public String getChannelPic() { return this.channelPic; } public void setChannelPic(String channelPic) { this.channelPic = channelPic; } public String getChannelDesc() { return this.channelDesc; } public void setChannelDesc(String channelDesc) { this.channelDesc = channelDesc; } public String getKeyWord() { return this.keyWord; } public void setKeyWord(String keyWord) { this.keyWord = keyWord; } /** * @return the sysRepeaterMng */ public SysRepeaterMng getSysRepeaterMng() { return sysRepeaterMng; } /** * @param sysRepeaterMng the sysRepeaterMng to set */ public void setSysRepeaterMng(SysRepeaterMng sysRepeaterMng) { this.sysRepeaterMng = sysRepeaterMng; } }
<?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"> <!-- Mapping file autogenerated by MyEclipse Persistence Tools --> <hibernate-mapping> <class name="com.ItemPublishFail" table="ITEM_PUBLISH_FAIL" schema="ZHENGJIANG" > <id name="itemId" type="java.lang.Long"> <column name="ITEM_ID" precision="6" scale="0" /> <generator class="sequence"> <param name="sequence">ITEMPUBLISHFAIL_SEQUENCE</param> </generator> </id> <property name="channelNam" type="java.lang.String"> <column name="CHANNEL_NAM" length="100" not-null="true" /> </property> <property name="channelTpid" type="java.lang.Integer"> <column name="CHANNEL_TPID" precision="3" scale="0" not-null="true" /> </property> <property name="mediaType" type="java.lang.String"> <column name="MEDIA_TYPE" length="10" not-null="true" /> </property> <property name="codeRate" type="java.lang.Integer"> <column name="CODE_RATE" precision="10" scale="0" not-null="true" /> </property> <property name="publishMode" type="java.lang.Integer"> <column name="PUBLISH_MODE" precision="1" scale="0" not-null="true" /> </property> <property name="pubPrv" type="java.lang.Integer"> <column name="PUB_PRV" precision="1" scale="0" not-null="true" /> </property> <property name="failTime" type="java.util.Date"> <column name="FAIL_TIME" length="7" not-null="true" /> </property> <property name="channelUrl" type="java.lang.String"> <column name="CHANNEL_URL" not-null="true" /> </property> <property name="channelPic" type="java.lang.String"> <column name="CHANNEL_PIC" not-null="true" /> </property> <property name="channelDesc" type="java.lang.String"> <column name="CHANNEL_DESC" length="256" /> </property> <property name="keyWord" type="java.lang.String"> <column name="KEY_WORD" length="30" /> </property> <many-to-one name="sysRepeaterMng" class="com.SysRepeaterMng" property-ref="reptSid" column="REPT_SID" cascade="none" outer-join="auto" access="property" not-null="true" lazy="false" > </many-to-one> </class> </hibernate-mapping>
问题一:属性fetch="join|select" 配置
hibernate 官方网站对 many-to-one 属性 fetch="join|select" 的解释:
fetch (optional - defaults to select): Chooses between outer-join fetching or sequential select fetching.
如果该属性设置成join 时,hibernate会使用 sql 中的 outer-join 来关联两张表取数据,如果设置成select时,则
hibernate会分别用两条select语句来取数据。
当使用Criteria 的 criteria.list();来取数据时,如果设置成select时,则hibernate会先将SysRepeaterMng 填充进
ItemPublishFail 中 再把数据填充到list 中,正确显示。
如果设置成join时则hibernate会分别将SysRepeaterMng 和 ItemPublishFail 对象都放入list中,造成错误,具体原因还不清楚。
问题二:属性property-ref配置(该属性适用于遗留的数据库,既与一方关联的不是主键,而是唯一键)
hibernate 数据库多对一关联时,如果一的那一方关联的字段不是表的主键,而是唯一键的话。则需要加另外的属性property-ref配置。
查看hibernate官方文档:
http://www.hibernate.org/hib_docs/v3/reference/en-US/html/mapping.html#mapping-declaration-manytoone
many-to-one 属性
property-ref: (optional) The name of a property of the associated class that is joined to
this foreign key. If not specified, the primary key of the associated class is used.
如果没有设置该属性,则hibernate会默认使用一方的主键,所以需要将该属性设置成一方的唯一键,这样hibernate在生成sql语句的时候才会正确使用唯一键来关联而不是使用主键关联。
发表评论
-
asm包冲突
2009-08-06 23:50 975配置完ssh后,启动tomcat,发现: ... -
com.mysql.jdbc.exceptions MySQLNonTransientConnectionException
2009-08-06 23:43 3311启动工程后,开始运 ... -
hibernate 级联插入
2009-08-05 12:42 2052映射文件见上一篇《hibernate 级联删除》 ... -
hibernate 级联删除
2009-08-04 10:49 3182配置文件和pojo类如下: <?xml vers ... -
org.hibernate.tuple.AbstractEntityTuplizer.createP
2009-06-30 12:42 1464hibernate配置文件: <hi ...
相关推荐
npm install node-fetch-with-proxy 用法 API与node-fetch相同。 const fetch = require ( 'node-fetch-with-proxy' ) ; fetch ( 'http://httpbin.org/get' ) . then ( res => res . json ( ) ) . then ( json =>...
grunt-fetch-from-cdn-源码.rar
前端开源库-fetch-as-audio-buffer提取为音频缓冲区,使用函数提取音频缓冲区
python库,解压后可用。 资源全名:fetch_data-0.2.3-py3-none-any.whl
/opt/nessus/sbin/nessuscli fetch --register-offline nessus.license Windows C:\\Program Files\\Tenable\\Nessus\\nessuscli.exe fetch --register-offline nessus.license macOS /Library/Nessus/run/sbin/...
fetch-manifest-json 从PWA获取mainfest.json。 安装 $ npm install --save fetch-manifest-json 用法 const fetchManifestJson = require ( 'fetch-manifest-json' ) ; fetchManifestJson ( < URL> ).then(console...
资源来自pypi官网。 资源全名:git-fetch-gitignore-0.0.2.tar.gz
从 CDN 中 grunt-fetch-from-cdn 这个 grunt 插件可以从 CDN 获取单个文件(比如 jquery.js)。 与 bower 不同,它只获取单个文件而不是整个项目。入门这个插件需要 Grunt ~0.4.4 如果您以前没有使用过 ,请务必查看...
Laravel开发-laravel-fetch-site-details 从其他网站获取详细信息,如标题、说明、语言、关键字…
vue-fetch-data:用于Vue组件提取数据的简单和声明性方法
$ npm install --save make-fetch-happen 目录 fetch.defaults minipass-fetch选项 make-fetch-happen选项 opts.cacheManager opts.cache opts.proxy opts.noProxy opts.ca, opts.cert, opts.key opts....
const fetch = require ( 'electron-main-fetch' ) ; ( async ( ) => { const response = await fetch ( 'https://api.ipify.org' ) ; console . log ( await response . text ( ) ) ; //=> '170.56.15.35' } ) ...
这些属性是可选的,除非需要fetch-retry时指定了其他默认值,否则这些属性将默认为3次重试,重试延迟为1000ms,并且仅在发生网络错误时重试。 require ( 'es6-promise' ) . polyfill ( ) ;var originalFetch = ...
资源来自pypi官网。 资源全名:fetch_data-0.2.3-py3-none-any.whl
fetch-react-native-components, 响应本机组件收集显示 响应本机组件列表在 npm registry 包中使用 react-native 关键字搜索,获取内部的'README.md'图片。更新日期:星期二 26 2016 09:: 10 GMT 0800 ( CST ) apsl-...
如何使用fetch-retry是一个下拉更换为fetch : const fetch = require ( '@vercel/fetch-retry' ) ( require ( 'node-fetch' ) )module . exports = async ( ) => { const res = await fetch ( '...
hibernate的类级别检索策略和检索策略的lazy、fetch、batch-size属性使用
fetch-rick-and-morty:从api提取快速练习
这将fetch作为全局添加,以便其API在客户端和服务器之间保持一致。 出于,该库将始终是polyfill。 作为不更改全局的“安全”替代方案,请考虑 。 为什么要使用同构提取 目前,Fetch API在各个浏览器上的。 此模块将...
可以从Bower安装d2l-fetch-siren-entity-behavior : bower install Brightspace/d2l-fetch-siren-entity-behavior 用法 将行为添加到您的组件中: < link rel = "import" href = "../../d2l-fetch-siren-...