[英]Any way to get a Hibernate SequenceGenerator from spring context?
The app in question is has spring define the LocalSessionFactoryBean for hibernate, and it loads the hibernate configuration from hibernate xml files. 有问题的应用程序是Spring为hibernate定义了LocalSessionFactoryBean,它从hibernate xml文件加载hibernate配置。 In the hibernate mapping files, the sequence generator class is specified. 在hibernate映射文件中,指定了序列生成器类。 Is there any way to specify a spring bean as a sequence generator rather than have hibernate create one based on the mapping configuration? 有没有办法将spring bean指定为序列生成器而不是让hibernate根据映射配置创建一个?
Short answer: no.
简答:不。
The problem is, that -even with hibernate4 support in spring 3.1- the spring classes are just 'wrappers' around
org.hibernate.cfg.Configuration
where
IdentifierGeneratorFactory
is read-only.
问题是,即使在春季3.1中使用hibernate4支持 - spring类只是
org.hibernate.cfg.Configuration
周围的'包装器',其中
IdentifierGeneratorFactory
是只读的。
(
http://docs.jboss.org/hibernate/core/3.6/javadocs/org/hibernate/cfg/Configuration.html )
(
http://docs.jboss.org/hibernate/core/3.6/javadocs/org/hibernate/cfg/Configuration.html )
Unless you subclass it and wrap it into spring, I see no way to accomplish this.
除非你将它子类化并将其包装到spring中,否则我认为无法实现这一点。
:(
:(
EDIT: 编辑:
Misread your question sorry. 误解你的问题抱歉。
You can create your own sequence generator ( https://community.jboss.org/wiki/CustomSequences ) , and if you create a factory for it, that factory can easily be made spring aware, and fully configurable and injectable from spring 您可以创建自己的序列生成器( https://community.jboss.org/wiki/CustomSequences ),如果您为它创建工厂,那么该工厂可以轻松实现弹簧识别,并且可以从弹簧中完全配置和注入
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.