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

  • SEARCH
  • Home
  • 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 7629369
In Process

The Archive Base Latest Questions

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

While working on a Spring 3 MVC project using Hibernate, we encountered an annoying

  • 0

While working on a Spring 3 MVC project using Hibernate, we encountered an annoying error. We are creating a carpool application. People can add routes (using the Gmap 3 plugin for jQuery) and can add waypoints to their route. In the database, a waypoint has a foreign key to a route. When trying to update a route (adding/removing waypoints and re-saving the route), we get the “found two representations of the same collection” error. We’ve researched the Internet but mostly the topics talk about the Play framework (we don’t use that) and furthermore they talk about annotations as mapping method (while we use XML mappings). Does anyone have any idea how we can fix this? Or is this a problem in Hibernate itself?

Some code to clarify the problem:

XML mapping of the route class:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="be.kdg.teamb.model.pojo.Route" table="route">
        <id name="routeid" type="java.lang.Integer">
            <generator class="identity"/>
        </id>
        <property name="departure" not-null="true"/>
        <property name="latitude_departure" />
        <property name="longtidude_departure" />
        <property name="destination" not-null="true"/>
        <property name="latitude_destination" />
        <property name="longtidude_destination" />
        <property name="departureTime" not-null="true" type="java.util.Date" />
        <property name="startDate" not-null="true" type="java.util.Date"/>
        <property name="endDate" type="java.util.Date" />
        <many-to-one name="driver" column="userid" not-null="true" cascade="save-update" />
        <many-to-one name="defaultCar" column="carid" not-null="true" cascade="save-                update"/>
        <set name="waypoints" cascade="all,delete-orphan" inverse="true">
            <key column="routeid" on-delete="cascade" />
            <one-to-many class="be.kdg.teamb.model.pojo.Waypoint" />
        </set>
        <set name="rides" cascade="all,delete-orphan" inverse="true">
            <key column="routeid" on-delete="cascade" />
            <one-to-many class="be.kdg.teamb.model.pojo.Ride"/>
        </set>
        <set name="rules" cascade="all,delete-orphan" inverse="true">
            <key column="routeid" on-delete="cascade" />
            <one-to-many class="be.kdg.teamb.model.pojo.RouteRule" />
        </set>
    </class>
</hibernate-mapping>

XML mapping of the waypoint class:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="be.kdg.teamb.model.pojo.Waypoint" table="waypoint">
        <id name="waypointid" type="java.lang.Integer">
            <generator class="identity"/>
        </id>
        <property name="latitude" not-null="true" />
        <property name="longtidude" not-null="true" />
        <property name="address" not-null="true" />
        <many-to-one name="route" column="routeid" not-null="true" cascade="all" />
    </class>
</hibernate-mapping>

Code in our serivce:

@Override
@Transactional
public void add(String departureCoordinates, String departure, String destinationCoordinates, String destination, String coordinatesWaypoints, String namesWaypoints, String user, int carID, Date beginDate, Date endDate, Date departureTime) {

    User usr = userDao.get(user);

    Route route = new Route();

    //formaat: latitude-longtitude
    String[] coords = departureCoordinates.split(",");

    String departureLatitude = coords[0];
    String departureLongtitude = coords[1];

    coords = destinationCoordinates.split(",");

    String destinationLatitude = coords[0];
    String destinationLongtitude = coords[1];

    // add route information
    route.setDeparture(departure);
    route.setLatitude_departure(departureLatitude);
    route.setLongtidude_departure(departureLongtitude);

    route.setDestination(destination);
    route.setLatitude_destination(destinationLatitude);
    route.setLongtidude_destination(destinationLongtitude);

    route.setDriver(usr);
    route.setDefaultCar(carDao.get(carID));

    route.setStartDate(beginDate);
    route.setDepartureTime(departureTime);
    route.setEndDate(endDate);

    if (coordinatesWaypoints != null && coordinatesWaypoints.trim().length() != 0) {
        String[] waypoints = coordinatesWaypoints.split(";;;");
        String[] waypointNames = namesWaypoints.split(";;;");

        int i = 0;

        for (String waypointAddress : waypointNames) {
            String[] waypointCoord = waypoints[i].split(",");

            String waypointLat = waypointCoord[0];
            String waypointLon = waypointCoord[1];

            Waypoint waypoint = new Waypoint();

            waypoint.setAddress(waypointAddress);
            waypoint.setLatitude(waypointLat);
            waypoint.setLongtidude(waypointLon);

            route.addWaypoint(waypoint);

            i++;
        }
    }
        else{
            for (Waypoint waypoint : route.getWaypoints()) {
                waypointDao.delete(waypoint);
            }


    }

    routeDao.save(route);

    socialMediaService.post(user, "http://localhost:8080/route/detail/" + route.getRouteid(), "Posted a new route! From " + route.getDeparture() + " to " + route.getDestination(), "Posted new route!", "Carpool teamb", "Posted a new route! From " + route.getDeparture());

}

The error stacktrace:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.HibernateException: Found two representations of same collection: be.kdg.teamb.model.pojo.Route.waypoints
 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
 org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
 org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
 org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173)
 org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
 org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
 org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
root cause

org.hibernate.HibernateException: Found two representations of same collection: be.kdg.teamb.model.pojo.Route.waypoints
 org.hibernate.engine.Collections.processReachableCollection(Collections.java:175)
 org.hibernate.event.def.FlushVisitor.processCollection(FlushVisitor.java:60)
 org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:122)
 org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:83)
 org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:77)
 org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:165)
 org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
 org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
 org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:58)
 org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1185)
 org.hibernate.impl.SessionImpl.list(SessionImpl.java:1261)
 org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
 org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:890)
 be.kdg.teamb.model.dao.impl.UserDaoImpl.get(UserDaoImpl.java:31)
 be.kdg.teamb.model.service.impl.UserServiceImpl.get(UserServiceImpl.java:222)
 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 java.lang.reflect.Method.invoke(Method.java:597)
 org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
 org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
 org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
 org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
 $Proxy33.get(Unknown Source)
 be.kdg.teamb.model.service.impl.SocialMediaServiceImpl.post(SocialMediaServiceImpl.java:36)
 be.kdg.teamb.model.service.impl.RouteServiceImpl.update(RouteServiceImpl.java:202)
 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 java.lang.reflect.Method.invoke(Method.java:597)
 org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
 org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
 $Proxy40.update(Unknown Source)
 be.kdg.teamb.controller.RouteController.edit(RouteController.java:258)
 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 java.lang.reflect.Method.invoke(Method.java:597)
 org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
 org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
 org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
 org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
 org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
 org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
 org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
 org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
 org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173)
 org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
 org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
 org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.25 logs.

Apache Tomcat/7.0.25

We also tried adding route.getWaypoints().clear(); but that didn’t seem to help.

Any suggestions on what to do? If you want more information, just ask.

  • 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:49:09+00:00Added an answer on May 31, 2026 at 5:49 am

    In the mapping of Waypoint class,

    <many-to-one name="route" column="routeid" not-null="true" cascade="all" />
    

    Just remove the cascade="all" and modify your mapping as below,

    <many-to-one name="route" column="routeid" not-null="true"  />
    

    Try to execute the code.

    You can also refer the blog post here or a thread on the hibernate discussion forums here. Read here on the usage of cascade option in hibernate.

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

Sidebar

Related Questions

I am working on a school project using Spring MVC (Spring 3.0.0). Now everything
While working on an existing project I suddenly got the following error when trying
While working a project tonight, I ended up using one .js resource file for
While working with Spring 3.x and and JSF 2.x, we can register the Spring
I am using spring + hibernate in my project; I have two classes Reminder
I have a working Spring MVC application(doing everything I wanted when deployed to jboss)
I am using Spring & Hibernate in my application and I want to set
I'm working on my first project using LINQ (in mvc), so there is probably
I'm working with MVC recently and I've encountered a strange problem while trying to
I am working on a project using Spring. I am trying to fetch a

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.