简体   繁体   English

在没有Spring的情况下使用Hibernate ORM

[英]Using Hibernate ORM without Spring

I'm writing a JavaFX Application which previously use Spring/QueryDSL for DI and persistence. 我正在编写一个JavaFX应用程序,该应用程序以前使用Spring / QueryDSL进行DI和持久性。

I'm hoping to move to using either Dagger or Guice (instead of spring) and Hibernate ORM. 我希望转而使用Dagger或Guice(而不是spring)和Hibernate ORM。

I have noticed that Spring offers some nice functionality on top of hibernate, such as transaction management via @Transactional. 我注意到,Spring在休眠状态之外还提供了一些不错的功能,例如通过@Transactional进行事务管理。

Are there other means of avoiding "boilerplate code" such as opening sessions, beginning transactions, committing transactions and closing sessions via some sort of hibernate configuration? 是否还有其他避免“样板代码”的方法,例如通过某种休眠配置来打开会话,开始事务,提交事务和关闭会话? Or are these features I'm really only going to get if I use Spring? 还是仅在使用Spring时才真正获得这些功能?

Guice has @Transactional support for JPA providers such as Hibernate using guice-persist , Dagger does not mention support for this. Guice使用guice-persist对JPA提供程序(例如Hibernate)提供@Transactional支持,Dagger没有提及对此的支持。

If you are using Hibernate as your JPA provider, using Spring with @Transactional would probably be the most natural fit for building your backend. 如果您将Hibernate用作JPA提供程序,则将Spring与@Transactional一起使用可能是构建后端的最自然选择。 You would find a loss less documentation, examples, blog posts, books and online help in general using other alternatives than with Spring/Hibernate. 与Spring / Hibernate相比,使用其他替代方法通常会减少文档,示例,博客文章,书籍和在线帮助的丢失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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