简体   繁体   English

有什么办法从Spring上下文中获取Hibernate SequenceGenerator?

[英]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.

相关问题 Spring 3应用程序中的Hibernate @SequenceGenerator问题 - Issue with Hibernate @SequenceGenerator in Spring 3 application Spring Hibernate @GeneratedValue & @SequenceGenerator 在本地查询中没有得到正确的序列 - Spring Hibernate @GeneratedValue & @SequenceGenerator didn't get correct sequence as querying by the native query JPA / Hibernate + Postgres SequenceGenerator - JPA/Hibernate + Postgres SequenceGenerator Hibernate,@ SequenceGenerator和allocationSize - Hibernate, @SequenceGenerator and allocationSize Hibernate:手动调用SequenceGenerator? - Hibernate: Call a SequenceGenerator manually? Hibernate实体中的多个SequenceGenerator - Multiple SequenceGenerator in Hibernate Entity @SequenceGenerator 的 initValue 和 allocationSize 被忽略,生成器没有分配给 @Id 字段(H2、HIbernate、Spring) - @SequenceGenerator's initValue and allocationSize are ignored and generator not assigned to @Id field (H2, HIbernate, Spring) Spring 4 + Tiles(3 || 2.2.2)-有什么方法可以在视图上下文中访问bean? - Spring 4 + Tiles (3 || 2.2.2) - Any way to access beans in view context? Hibernate @SequenceGenerator 在 MS SQL 中返回不正确的值 - Hibernate @SequenceGenerator return incorrect value in MS SQL spring 如何从应用程序上下文中获取 BeanFactory - spring how to get BeanFactory from Application Context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM