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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:53:06+00:00 2026-06-17T09:53:06+00:00

I’m facing a weird problem. I’m currently writing a web application based on Spring-MVC

  • 0

I’m facing a weird problem. I’m currently writing a web application based on Spring-MVC 3.2, and Hibernate 4.1.9. I wrote a sample controller with its TestNG unit tests, and everything is fine except for editing. I can see that when saving a new object, it works like a charm, but if I try to edit an existing object, it doesn’t get saved without giving out any reason (I’m calling the same method for adding and updating).

The log of adding a new object of type Application

14:26:36.636 [main] DEBUG o.s.t.w.s.TestDispatcherServlet - DispatcherServlet with name '' processing POST request for [/app/add.json]
14:26:36.637 [main] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /app/add.json
14:26:36.650 [main] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Returning handler method [public java.lang.Long com.wstars.kinzhunt.platform.apps.web.AppController.createApp(com.wstars.kinzhunt.platform.model.apps.Application)]
14:26:36.651 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'appController'
14:26:36.821 [main] DEBUG o.s.w.s.m.m.a.RequestResponseBodyMethodProcessor - Reading [class com.wstars.kinzhunt.platform.model.apps.Application] as "application/json" using [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter@5dc6bb75]
14:26:36.890 [main] DEBUG o.s.o.hibernate3.SessionFactoryUtils - Opening Hibernate Session
14:26:36.890 [main] DEBUG org.hibernate.impl.SessionImpl - opened session at timestamp: 13580799968
14:26:36.892 [main] DEBUG c.w.c.dao.hibernate.BaseDaoHibernate - Saving or Updating Object: com.wstars.kinzhunt.platform.model.apps.Application@54fc519b[id=<null>,name=KinzHunt,company=com.wstars.kinzhunt.platform.model.apps.Company@151c2b4[id=1,name=KinzHunt],callbackUrl=http://www.kinzhunt.com/callback/,website=http://www.kinzhunt.com,senderEmail=no-reply@kinzhunt.com,logoUrl=<null>]
14:26:36.892 [main] DEBUG o.s.o.hibernate3.SessionFactoryUtils - Opening Hibernate Session
14:26:36.893 [main] DEBUG org.hibernate.impl.SessionImpl - opened session at timestamp: 13580799968
14:26:36.893 [main] DEBUG o.s.o.hibernate3.SessionFactoryUtils - Closing Hibernate Session
14:26:36.894 [main] DEBUG o.h.e.def.AbstractSaveEventListener - executing identity-insert immediately
14:26:36.898 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
14:26:36.899 [main] DEBUG org.hibernate.jdbc.ConnectionManager - opening JDBC connection
14:26:36.899 [main] DEBUG o.s.j.d.DriverManagerDataSource - Creating new JDBC DriverManager Connection to [jdbc:h2:mem:platform_test;DB_CLOSE_DELAY=-1]
14:26:36.901 [main] DEBUG org.hibernate.SQL - /* insert com.wstars.kinzhunt.platform.model.apps.Application */ insert into applications (id, callback_url, company_id, logo_url, name, sender_email, website) values (null, ?, ?, ?, ?, ?, ?)
14:26:36.904 [main] DEBUG o.h.id.IdentifierGeneratorHelper - Natively generated identity: 2
14:26:36.904 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
14:26:36.905 [main] DEBUG o.s.o.hibernate3.SessionFactoryUtils - Closing Hibernate Session
14:26:36.905 [main] DEBUG org.hibernate.jdbc.ConnectionManager - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
14:26:36.905 [main] DEBUG org.hibernate.jdbc.ConnectionManager - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
14:26:36.926 [main] DEBUG o.s.w.s.m.m.a.RequestResponseBodyMethodProcessor - Written [2] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter@5dc6bb75]
14:26:36.927 [main] DEBUG o.s.t.w.s.TestDispatcherServlet - Null ModelAndView returned to DispatcherServlet with name '': assuming HandlerAdapter completed request handling
14:26:36.928 [main] DEBUG o.s.t.w.s.TestDispatcherServlet - Successfully completed request

While the log for saving an edited object is

14:27:03.398 [main] DEBUG o.s.t.w.s.TestDispatcherServlet - DispatcherServlet with name '' processing POST request for [/app/1/edit.json]
14:27:03.398 [main] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /app/1/edit.json
14:27:03.401 [main] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Returning handler method [public java.lang.Long com.wstars.kinzhunt.platform.apps.web.AppController.editApp(com.wstars.kinzhunt.platform.model.apps.Application,java.lang.Long)]
14:27:03.401 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'appController'
14:27:03.404 [main] DEBUG o.s.w.s.m.m.a.RequestResponseBodyMethodProcessor - Reading [class com.wstars.kinzhunt.platform.model.apps.Application] as "application/json" using [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter@5dc6bb75]
14:27:03.409 [main] DEBUG o.s.o.hibernate3.SessionFactoryUtils - Opening Hibernate Session
14:27:03.410 [main] DEBUG org.hibernate.impl.SessionImpl - opened session at timestamp: 13580800234
14:27:03.411 [main] DEBUG c.w.c.dao.hibernate.BaseDaoHibernate - Saving or Updating Object: com.wstars.kinzhunt.platform.model.apps.Application@1ba4f8a6[id=1,name=KinzHunt,company=com.wstars.kinzhunt.platform.model.apps.Company@6bc06877[id=1,name=KinzHunt],callbackUrl=http://www.kinzhunt.com/callback/,website=http://www.wstars.com/KinzHunt/,senderEmail=no-reply@kinzhunt.com,logoUrl=<null>]
14:27:03.412 [main] DEBUG o.s.o.hibernate3.SessionFactoryUtils - Opening Hibernate Session
14:27:03.412 [main] DEBUG org.hibernate.impl.SessionImpl - opened session at timestamp: 13580800234
14:27:03.413 [main] DEBUG o.s.o.hibernate3.SessionFactoryUtils - Closing Hibernate Session
14:27:03.422 [main] DEBUG o.s.o.hibernate3.SessionFactoryUtils - Closing Hibernate Session
14:27:03.424 [main] DEBUG o.s.w.s.m.m.a.RequestResponseBodyMethodProcessor - Written [1] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter@5dc6bb75]
14:27:03.424 [main] DEBUG o.s.t.w.s.TestDispatcherServlet - Null ModelAndView returned to DispatcherServlet with name '': assuming HandlerAdapter completed request handling
14:27:03.425 [main] DEBUG o.s.t.w.s.TestDispatcherServlet - Successfully completed request

As you can see, in the second log, no prepared statement is created, and no JDBC connection is opened. My test configuration for the database is like this:

<bean id="targetDataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.h2.Driver" />
    <property name="url" value="jdbc:h2:mem:platform_test;DB_CLOSE_DELAY=-1" />
</bean>

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="targetDataSource" />
    <property name="packagesToScan">
        <list>
            <value>com.mypackage.model.*</value>
        </list>
    </property>
    <property name="namingStrategy">
        <bean class="com.example.common.config.MyOwnNamingStrategy"/>
    </property>
    <property name="hibernateProperties">
        <map>
            <entry key="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
            <entry key="hibernate.max_fetch_depth" value="1" />
            <entry key="hibernate.use_sql_comments" value="true" />
            <entry key="hibernate.hbm2ddl.auto" value="update" />
        </map>
    </property>
    <!-- <property key="hibernate.current_session_context_class" value="thread"/> -->
    <!-- <property key="hibernate.transaction.factory_class" value="org.hibernate.transaction.JDBCTransactionFactory"/> -->
</bean>

<bean id="h2WebServer" class="org.h2.tools.Server"
    factory-method="createWebServer" depends-on="targetDataSource"
    init-method="start" lazy-init="false">
    <constructor-arg value="-web,-webPort,11111" />
</bean>

My controller code is:

@Controller
public class AppController extends BaseAnnotatedController {

    @Autowired
    private AppManagementService appManagementService;

    @RequestMapping(value="/app/add", method=RequestMethod.POST, consumes={"application/json"})
    public @ResponseBody Long createApp(@RequestBody Application app) {
        saveApp(app);
        return app.getId();
    }

    @RequestMapping(value="/app/{appId}/edit", method=RequestMethod.POST, consumes={"application/json"})
    public @ResponseBody Long editApp(@RequestBody Application app, @PathVariable Long appId) {
        if (!appId.equals(app.getId())) {
            WSError error = new WSError(ValidationErrorType.GENERIC, "id");
            throw new ValidationException(error);
        } else {
            saveApp(app);
            return app.getId();
        }
    }

    @RequestMapping(value="/app/list", method=RequestMethod.GET)
    public @ResponseBody List<Application> listApps() {
        return appManagementService.listAllApps();
    }

    @RequestMapping(value="/app/{appId}/get", method=RequestMethod.GET)
    public @ResponseBody Application getAppDetails(@PathVariable Long appId) {
        return appManagementService.getApplication(appId);
    }

    private void saveApp(Application app) {
        if (isValid(app)) {
            appManagementService.saveApp(app);
        }
    }

    public @ResponseBody List<Application> listAllApps() {
        return appManagementService.listAllApps();
    }
}

My test class is:

@Test
public class AppControllerIntegrationTests extends AbstractContextControllerTests {

    private MockMvc mockMvc;

    @Autowired
    AppController appController;

    @Autowired
    private AppManagementService appManagementService;

    @Autowired
    private BaseDao baseDao;

    @BeforeClass
    public void classSetup() {
        Company comp = new Company();
        comp.setName("Some Company");
        baseDao.saveObject(comp);
    }

    @BeforeMethod
    public void setup() throws Exception {
        this.mockMvc = webAppContextSetup(this.wac).build();
    }

    @Test
    public void testAddInvalidAppWebJson() throws Exception {
        String appJson = getInvalidApp().toJsonString();
        RequestBuilder requestBuilder = MockMvcRequestBuilders.post("/app/add.json")
                .contentType(MediaType.APPLICATION_JSON).content(appJson);
        ResultActions resultAction = this.mockMvc.perform(requestBuilder);
        resultAction.andExpect(status().isForbidden());
        MvcResult mvcResult = resultAction.andReturn();
        Exception resolvedException = mvcResult.getResolvedException();
        assertTrue(resolvedException instanceof ValidationException);
        ValidationException validationException = (ValidationException) resolvedException;
        assertEquals(validationException.getErrors().size(), 3);
    }

    @Test
    public void testAddAppWebJson() throws Exception {
        Application app = getMockApp();
        String appJson = app.toJsonString();
        RequestBuilder requestBuilder = MockMvcRequestBuilders.post("/app/add.json")
                .contentType(MediaType.APPLICATION_JSON).content(appJson);


        this.mockMvc.perform(requestBuilder).andExpect(status().isOk());

    }

    @Test
    public void testEditAppWithWrongIdWebJson() throws Exception {
        String appJson = getMockAppWithId().toJsonString();
        RequestBuilder requestBuilder = MockMvcRequestBuilders.post("/app/2/edit.json")
                .contentType(MediaType.APPLICATION_JSON).content(appJson);
        this.mockMvc
                .perform(requestBuilder)
                .andExpect(status().isForbidden())
                .andExpect(
                        content()
                                .string("{\"errors\":[{\"errorType\":\"-100\",\"field\":\"id\",\"constraint\":null}],\"objects\":null}"));
    }

    @Test(dependsOnMethods={"testAddApp", "testAddAppWebJson"})
    public void testEditAppWebJson() throws Exception {
        Application app = getMockAppWithId();
        setAppWebsiteToDifferentOne(app);
        String appJson = app.toJsonString();

        RequestBuilder requestBuilder = MockMvcRequestBuilders.post("/app/1/edit.json")
                .contentType(MediaType.APPLICATION_JSON).content(appJson);

        this.mockMvc.perform(requestBuilder).andExpect(status().isOk());
    }

    @Test
    public void testEditInvalidAppWebJson() throws Exception {
        Application app = getMockAppWithId();
        app.setWebsite("Saba7o 3asal");
        String appJson = app.toJsonString();
        RequestBuilder requestBuilder = MockMvcRequestBuilders.post("/app/1/edit.json")
                .contentType(MediaType.APPLICATION_JSON).content(appJson);
        this.mockMvc
                .perform(requestBuilder)
                .andExpect(status().isForbidden())
                .andExpect(
                        content()
                                .string("{\"errors\":[{\"errorType\":\"-114\",\"field\":\"website\",\"constraint\":null}],\"objects\":null}"));
    }

    @Test(dependsOnMethods="testEditAppWebJson")
    public void testGetAppDetails() throws Exception {
        RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/app/1/get.json");
        Application app = getMockAppWithId();
        setAppWebsiteToDifferentOne(app);

        this.mockMvc.perform(requestBuilder).andExpect(status().isOk())
                .andExpect(content().string(app.toJsonString()));
    }
}

My service method is:

@Override
@Transactional(readOnly=false)
public void saveApp(Application app) {
    baseDao.saveObject(app);
}

All test methods pass, except for the last one, since it’s expecting the website of the app to be the one which was edited. Where have I gone wrong?

  • 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-06-17T09:53:07+00:00Added an answer on June 17, 2026 at 9:53 am

    Need to know which hibernate method is called in saveApp() also make sure your service is annotated with @Transactional.

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

Sidebar

Related Questions

I've tracked down a weird MySQL problem to the two different ways I was
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported
I'm interested in microtypography issues on the web. I want a tool to fix:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.