1
我有休眠编写自定义SequenceGenerator:我如何注入弹簧豆成休眠SequenceGenerator
public class LoginGenerator extends SequenceGenerator {
@Autowired
ITicketService ticketService;
@Override
public Serializable generate(SessionImplementor session, Object obj) {
Ticket ticket = (Ticket) obj;
Long maxCounterOfSection = ticketService.findMaxSectionCounter(ticket
.getSection());
maxCounterOfSection++;
return ticket.getSection() + "-" + maxCounterOfSection;
}
}
但是我没有这个发生器内弹簧背景! ticketService为null。我已经为我的发电机尝试了@Component注解,但没有成功。
PS:我使用spring 3.2.0-FINAL和hibernate 3.6.10-FINAL,并且没有办法更新到hibernate4!
任何想法,任何人?
这哪里是应用程序中运行?你如何创建你的春天背景? – Farzad
应用程序在Tomcat中作为web应用程序运行。但是这并不重要,因为我也在junit测试中运行SpringJUnit4ClassRunner和@ContextConfiguration时出错。 –
生成器没有被Spring实例化,所以你不能注入任何东西。 Hibernate不是基于Spring的。 –