简体   繁体   中英

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. In the hibernate mapping files, the sequence generator class is specified. Is there any way to specify a spring bean as a sequence generator rather than have hibernate create one based on the mapping configuration?

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. ( 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. :(

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM