Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7627105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:24:56+00:00 2026-05-31T05:24:56+00:00

I am using Guice, Guice Persist, Hibernate and Jersey. All my resource methods are

  • 0

I am using Guice, Guice Persist, Hibernate and Jersey. All my resource methods are annotated with @Transactional except for the methods that are annotated with @GET. Is this the correct way configure the transaction-per-request scope?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:24:57+00:00Added an answer on May 31, 2026 at 5:24 am

    There is no “correct” way; it depends on what you are trying to achieve. There is a few separate issues involved in answering your question, as discussed below.

    1. Data access pattern: The traditional pattern in enterprise Java is to have your controllers make calls to DAOs (Data Access Objects), which handle persistence. In this pattern, your transaction annotations would be placed on the DAO methods, not your controller methods. However, many people find DAOs to be overkill and prefer to have the entity manager injected into the controller. This is a perfectly acceptable alternative and, from what I can tell, this is the approach you have chosen.
    2. Thread safety: You must be aware that entity manager instances are not thread safe, so your controllers must not be singletons and must be request-scoped. In other words, you cannot share an entity manager across multiple requests, so you must set your controllers to be re-created and have a new entity manager injected for every request.
    3. Transactions: If your data retrieval operation only requires one query, you will not require a transaction. However, building a complete object graph generally requires many queries. In this circumstance, your retrieval must be transactional in order to guarantee consistency, because the data might change between queries. Some frameworks will actually require all database access to be transactional, or the entity manager will not be injected correctly.

    In summary, your data access pattern is fine, as long as your controllers are request-scoped. However, your “GET” functions should be transactional if many queries will be involved in creating the object graph.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to achieve the following using guice/gin: Get all sort
I'm using an environment with guice-servlet running on a tomcat and hibernate under guice-persist.
I using Hibernate 3.6 Final, Guice-persist and JPA2. So good, I have everything configured,
I'm trying to use construction injection using both Jersey-injected @Context parameters and Guice-injected parameters.
I'm using Google Guice with Jersey (jax-rs). Following method throws an JAXB-Exception (JAXB can't
I'm using a UnitOfWork in a background task method (operated by Quartz) with Guice-persist
Is there any generally accepted, proven-to-work way using hibernate, that keeps a history of
I'm looking how I could get an Injector using Guice in a web application.
I am using Jersey Guice and need to configure a custom ExceptionMapper My module
It seems that all Guice's out-of-the-box Scope implementations are inherently Thread-based (or ignore Threads

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.