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