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 7619103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:34:25+00:00 2026-05-31T03:34:25+00:00

Background I am trying to implement a RESTful web service using Apache-CXF that interacts

  • 0

Background

I am trying to implement a RESTful web service using Apache-CXF that interacts with a database to do some CRUD operations via Hibernate. The web service consumes and produces JSON formatted objects using the Jackson JAX-RS Provider.

I am currently receiving a “failed to lazily initialize a collection… no session or session was closed” exception that is bubbling up from the Jackson provider when it attempts to serialize the response object.

I assumed that if I marked the service method with @Transactional that the session would be available to the Jackson provider when it serialized the response, but that does not appear to be the case.

Question

How do I get the hibernate session to be available while Jackson is walking the object during serialization?

What I’ve Tried

Spring Configuration

<context:component-scan base-package="com.db.cif.mapper" />
<context:component-scan base-package="com.db.cif.mapper.repository" />
<context:annotation-config />

<tx:jta-transaction-manager>
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</tx:jta-transaction-manager>

<tx:annotation-driven />

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="cifmapper" />
    <property name="jpaDialect">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
    </property>
</bean>

<!-- JAX-RS Configuration -->
<jaxrs:server id="mappingService" address="/">
    <jaxrs:serviceBeans>
        <ref bean="mappingServiceBean" />
    </jaxrs:serviceBeans>
    <jaxrs:extensionMappings>
        <entry key="json" value="application/json" />
    </jaxrs:extensionMappings>
    <jaxrs:providers>
        <ref bean="jsonProvider" />
    </jaxrs:providers>
</jaxrs:server>

<bean id="mappingServiceBean" class="com.db.cif.mapper.MappingService" />

<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" />

Service Bean

@Service("mappingService")
@Transactional
public class MappingService 
{
    private static final Logger logger = Logger.getLogger(MappingService.class);

    @Autowired
    @Qualifier("mappingRepository")
    private MappingRepository mappingRepository;

    @GET
    @Path("/collections/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    public Collection getCollection(@PathParam("id") String id)
    {
        if(logger.isDebugEnabled())
        {
            logger.debug(String.format("Invoked getCollection, Collection id: %s", id));
        }

        return this.mappingRepository.getCollection(id);
    }

    @POST
    @Path("/collections/")
    @Consumes(MediaType.APPLICATION_JSON)
    public Response addCollection(Collection collection)
    {
        if(logger.isDebugEnabled())
        {
            logger.debug(String.format("Invoked addCollection, Collection: %s", collection));
        }

        this.mappingRepository.createCollection(collection);

        return Response.ok(collection).build();
    }
}

Collection Bean

@Entity
@Table(schema = "CIFMAPPER", name = "COLLECTION")
public class Collection implements Serializable
{
    private static final long serialVersionUID = 1579878442412232635L;

    @Id
    @Column(name = "ID")
    private String id;

    @Column(name = "SRC_ENDPT_ID", nullable = false, insertable = false, updatable = false)
    private long sourceEndpointId;

    @Column(name = "DEST_ENDPT_ID", nullable = false, insertable = false, updatable = false)
    private long destinationEndpointId;

    @Column(name = "DESCRIPTION")
    private String description;

    @Column(name = "START_DATE", nullable = false)
    private Date startDate;

    @Column(name = "END_DATE")
    private Date endDate;

    @ManyToOne(optional = false)
    @JoinColumn(name = "SRC_ENDPT_ID")
    private Endpoint source;

    @ManyToOne(optional = false)
    @JoinColumn(name = "DEST_ENDPT_ID")
    private Endpoint destination;

    @OneToMany(mappedBy = "collection", targetEntity = MappingGroup.class, fetch = FetchType.EAGER)
    private List<MappingGroup> mappingGroups;

//Getters and Setters Removed For Brevity
}
  • 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-31T03:34:26+00:00Added an answer on May 31, 2026 at 3:34 am

    While I believe there is a way to make that work (using a Filter or intercepetor that opens and closes the session), I think the right answer is: don’t have lazy collections and proxies. Configure your mappings so that you don’t have lazy collections.

    An alternative approach is to manually initialize them. This is often combined with DTOs – objects with a similar structure to the entities that are used as responses to other components (so that you are not directly exposing entities). So your methods return OrderDTO rather than Order, where the DTO contains as many fields as you need to return to the caller. You manually transfer the values from the entity to the DTO.

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

Sidebar

Related Questions

I am trying to implement search on a background thread using NSOperation on iOS
First, some background: I am trying to implement a master-detail interface in Cocoa (for
I am trying to implement background music into an Android game that I am
A little background info - I'm trying to host a RESTful WCF service on
Background I'm trying to implement a simple web server part as a web interface
I am trying to implement a background service to transmit logs from a calllog
I'm trying to implement a design in CSS that will have a tiled background
I am trying to implement an application for iPhone that should simply download some
Some background: Im trying to implement the integration of Cruisecontrol (2.8.4), MSBuild and MSTest
Background: I'm trying to create a pure D language implementation of functionality that's roughly

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.