iteye_9642 2010-05-06 21:29
浏览 283
已采纳

pojo中的域并不在数据库中存在,hibernate如何定义

hibernate 映射的class的变量可以定义多于数据库中的域么?pojo中的域并不在数据库中存在,hibernate如何定义

即类似 grails中class定义中的transients属性

即:pojo中的值并不在数据库中存在

如中间变量或数据

当然,多添加个BO来做没问题,再赋值,再保存。感觉没必要而已。就如grails中,直接赋予transients属性就很简单


搜索了下,貌似无解

http://jira.codehaus.org/browse/GRAILS-4978

与我提的问题有点反方向,但解答有关:

In effect, transient properties are not part of Hibernate (annotation) mapping meta data and this appears to be very reasonable, as @Transient states just that Hibernate should completely ignore a particular property.
Within org.codehaus.groovy.grails.orm.hibernate.GrailsHibernateDomainClass, Grails then uses these meta data to construct the properties of the persistent class. This will result in transient properties missing from the properties collection of a persistent class

For your example, transientField will not be a member of myDomainInstance.properties but can still be accessed via myDomainInstance.transientField.
As the scaffolding logic uses the properties from the persistent class, it will just not see any transient property.
A fix might require GrailsHibernateDomainClass to introspect the persistent class on its own and to merge those properties with the properties from the meta class - provided there is a way to add properties that are not mapped by Hibernate.
A work-around might be attempted by adding missing properties within application code, but I suspect it may not be a task for the faint of heart


嘿嘿,貌似扩展个类,再upcasting就行了,试试看。----我自言自语ing

  • 写回答

2条回答 默认 最新

  • 拽拽的初行者 2010-05-07 12:04
    关注

    如果是用Annotation的话 就用 @Transient

    如果是用XML的话,就不再XML中配置

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块