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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:08:05+00:00 2026-06-12T10:08:05+00:00

I am trying to learn MongoDB and in the same time write a simple

  • 0

I am trying to learn MongoDB and in the same time write a simple REST application using Spring framework.

I have a simple model:

@Document
public class Permission extends documentBase{

@Indexed(unique = true)
private String name;

public   Permission(String name) {
    this.name = name;       
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}
}

Then I have a simple DAO:

@Repository
@Transactional 
@Profile({"production","repositoryTest","mongoIntegrationTest"})
public class DaoImpl   implements DAO  {

@Autowired
protected MongoTemplate mongoTemplate;

public <T> T addObject(T object) {               
     mongoTemplate.insert(object);        
     return object; 
}

The I have my integration tests:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:mvc-dispatcher-servlet.xml", classpath:IntegrationContext.xml"},loader = TestXmlContextLoader.class)
@ActiveProfiles("mongoIntegrationTest")
public class RepositoryIntegrationTest extends AccountTestBase{

    @Autowired DAO repository;
    @Autowired WebApplicationContext wac;

    @Test
public void AddPermission() { 
    Permission permission_1 = new Permission("test");           
    Permission permission_2 = new Permission("test");           
    repository.addObject(permission_1);
    repository.addObject(permission_2);
}
}

My configuration:

 <!-- MongoDB host -->
 <mongo:mongo host="${mongo.host.name}" port="${mongo.host.port}"/> 

 <!-- Template for performing MongoDB operations -->
 <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate" 
c:mongo-ref="mongo" c:databaseName="${mongo.db.name}"/>

I am expecting that, on adding “permission_2” their would be a exception thrown from MongoDB, which would be translated by Spring,, and catched as a DataAccessException in the DAO.

Looking at the log files from MongoDb I can see that a duplicated exception is thrown but it never reaches my DAO.

So,, I guess I am doing something wrong,,, but at the moment,, I am blind to my own misstakes.

//lg

  • 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-12T10:08:06+00:00Added an answer on June 12, 2026 at 10:08 am

    Make sure you configure the WriteConcern of the MongoTemplate to something non-default (e.g. WriteConcern.SAFE). By default MongoDB is in fire-and-forget mode and does not throw exceptions on index violations or server errors in general.

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

Sidebar

Related Questions

Im trying to learn how to set up a Zend framework web application from
I come from MySQL background and I am trying to learn MongoDB. I have
I trying to learn web application development. I'm currently using Google App Engine to
Trying to learn Haskell. I am trying to write a simple function to remove
Im trying to learn Sync framework. I have followed step by step MSDN Documentation
I am trying to learn to develop a web application (preferably NodeJS/MongoDB, although I
Trying to learn about php's arrays today. I have a set of arrays like
Im trying to learn a bit about c++ and have run in to some
I am currently trying to learn Ruby On Rails as I am a long-time
I was trying learn lex and yacc using the oreilly book. I tried following

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.