Hibernate代理ID值(Hibernate proxy id value)
我发现了一些类似的问题,但不是确切的问题。
对于HibernateProxy实例(延迟加载),可以使@Id注释字段包含实际的id值。
我可以在调试器中看到该ID是已知的,并且包含在关联的LazyInitializer实现中。 但是为什么它没有放入实际实体/代理对象的相应ID字段?
这样做的唯一方法显然是使用getId()访问器方法和@Access(AccessType.PROPERTY)的精巧技巧。 如果可以避免这种情况会很棒。
I found some mentions of similar questions, but not this exact question.
For a HibernateProxy instance (lazy loaded), can the @Id annotated field be made to contain the actual id value.
I can see in a debugger that the ID is known, and contained in the associated LazyInitializer implementation. But why is it not also put in the corresponding ID field of the actual entity/proxy object?
The only way to do this is apparently an elaborate trick using getId() accessor method and @Access(AccessType.PROPERTY). It would be great if this could be avoided.
原文:https://stackoverflow.com/questions/33524744
最满意答案
你可以通过将
cast
函数与模式保护相结合来相对简单地完成它:f :: Typeable a => a -> Any f x | Just s <- cast x = IsString s | Just n <- cast x = IsInt n | otherwise = IsUndefined
这确实要求输入是
Typeable
一个实例,但是大多数标准类型都有一个deriving Typeable
子句,所以它通常不是问题。You can do it relatively simply by combining the
cast
function with pattern guards:f :: Typeable a => a -> Any f x | Just s <- cast x = IsString s | Just n <- cast x = IsInt n | otherwise = IsUndefined
That does require that the input be an instance of
Typeable
, but most standard types have aderiving Typeable
clause so it's usually not a problem.
相关问答
更多-
你是正确的,因为构造函数本质上只是函数,所以你可以通过编写函数的实例来为任意数量的类型编写泛型实例。 但是,您仍然需要为所有不同数量的参数编写单独的实例。 {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} import Text.Read import Control.Applicative class FieldParser p r where parseFields :: p -> [Strin ...
-
好吧,这似乎与ghc 7.8.4有关。 我尝试了与ghc 7.10.1相同的代码片段并编译。 Ok, this seems to be related to ghc 7.8.4. I tried the same code snippet with ghc 7.10.1 and it compiled.
-
要为此定义mutualy递归类型或函数,您可以使用关键字and 。 在您的情况下,您的记录看起来像这样: type selectionSet = { t : t; selections : selections list; } and selections = { name : name; selectionSet : selectionSet option; } To define mutualy recursive types or functions for that matter ...
-
定义的数据类型没有定义?(A defined data type not defined?)[2021-11-20]
从你的编辑,你有 data SegmentList = SegmentList SegmentlistHeader [Segment] | AugmentedSegmentList SegmentlistHeader [AugmentedSegment] deriving (Show) data Segment = Segment SegmentLabel SegmentStart SegmentEnd Session Checksum | AugmentedSeg ... -
明确的缩小范围(Well defined narrowing cast)[2021-08-18]
这是一个使用一点C ++ 11的版本。 如果您无权访问constexpr ,则可以将其删除。 如果你没有访问std::make_unsigned ,可以实现你自己的。 如果你没有std::enable_if ,你可以使用Boost's(或者自己制作)。 它适用于有符号和无符号类型,以及正值和负值。 更新 :更新为使用浮点类型(浮点到积分,反之亦然)。 #include// From integer type to integer type template 使用Data.Typeable的强制转换使用本地定义的数据类型(Using Data.Typeable's cast with a locally defined data type)[2023-06-13]
你可以通过将cast函数与模式保护相结合来相对简单地完成它: f :: Typeable a => a -> Any f x | Just s <- cast x = IsString s | Just n <- cast x = IsInt n | otherwise = IsUndefined 这确实要求输入是Typeable一个实例,但是大多数标准类型都有一个deriving Typeable子句,所以它通常不是问题。 You can do it relatively sim ...Haskell GHC-7.6.2使用HashMap导出数据和可输入(Haskell GHC-7.6.2 deriving Data and Typeable with HashMap)[2021-11-01]
它不仅适用,而且适用于Linux上的GHC 7.6.3 x86-64。 也许这是7.6.2的bug? 我会查看更改日志。 Having experimented a bit, I found that unordered-containers-0.2.2.1 shipped with Ubuntu 13.04 is incompatible with ghc-7.6.2 (also shipped by Ubuntu). When I install the latest unordered-contain ...你说你想要检查是否平等。 只需使用equals(Object o) 。 它在Object上声明,并接受Object作为参数。 实现将在运行时动态绑定。 public void setSingleLimit(String columnName, Object limit){ Object columnValue = getValue(columnName); limit.equals(columnValue); // If limit can be null, swap variables } ...不存在量化方法时重叠实例错误的原因(Reason for overlapping instances error when not quantifying method existentially)[2022-02-10]
这是作用域类型变量在Haskell中的工作方式。 请注意,您在此处重复使用r : go :: forall r a . (Typeable a, Typeable (D r)) => a -> Proxy r -> A go a _ = case cast a of Just (b :: D r) -> A b -- this r is the same as the r above 如果没有显式的forall ,则类型变量将被解释为签名的本地变量。 也就是说,您的代码读作: go :: (Type ...数据系列和可输入数据(Data Families and Typeable)[2024-03-09]
如果使用-ddump-deriv查看派生的输出,您会看到每个数据族实例声明都生成了相同的instance Typeable1 DF 。 data family DF a data instance DF Int = DFInt deriving (Typeable) data instance DF Char = DFChar deriving (Typeable) 给 instance Data.Typeable.Internal.Typeable1 Main.DF where Data.Typea ...相关文章
更多- js 通过td的id值 如何拿到tr的id值?
- hibernate id 生成策略及主要使用方法
- MongoDB _id和ObjectId详解
- EXT Tree叶子节点的ID如何存储到Store的HttpProxy参数中?
- solr required field: id
- html中一个div的id是“1:222”的话,怎么利用id给它定义css啊?
- Solr4.0 如何配置使用UUID自动生成id值
- Solr4.0 如何配置使用UUID自动生成id值
- mysql in根据查询id排序
- 配置solr自动生成id
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。