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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:51:16+00:00 2026-06-07T12:51:16+00:00

I’m using Hibernate 4.0.1.Final with a MySQL 5.5 database. I’m writing a Java console

  • 0

I’m using Hibernate 4.0.1.Final with a MySQL 5.5 database. I’m writing a Java console app. In a JUnit test, I’m having trouble getting a test to fail. Here’s my models under test …

@Entity
@Table(name = "ic_domain")
public class Domain {

    @Id
    @Column(name = "DOMAIN_ID")
    private String domainId;

    @OneToOne(fetch = FetchType.EAGER, targetEntity = Organization.class)
    @JoinColumn(name = "ORGANIZATION_ID")
    private Organization org;

and

@Entity
@Table(name = "ic_organization")
public class Organization {

    @Id
    @Column(name = "ORGANIZATION_ID")
    private String organizationId;

My problem is, in my JUnit test, I’m trying to create a foreign key that doesn’t exist, expecting things to fail upon saving, but they never do. Here’s the JUnit test

@Test
public void testSaveDomainWithUnmathcedOrg() { 
    final Organization org = createDummyOrg();
    // Create an org id that doesn't exist.
    org.setOrganizationId("ZZZZ");
    final Domain domain = new Domain();
    final String id = UUID.randomUUID().toString().replace("-", "");
    domain.setDomainId(id);
    domain.setName(org.getName());
    domain.setOrg(org);
    m_domainDao.saveOrUpdate(domain);   
}   // testSaveDomainWithUnmatchedOrg

The code of the DAO is

public void saveOrUpdate(final Domain domain) {
    final Session session = sessionFactory.getCurrentSession();
    session.saveOrUpdate(obj);
}   // saveOrUpdate

Shouldn’t things fail at “session.saveOrUpdate”? How do I make them? I don’t want to commit my data in the JUnit test because I don’t want to pollute the underlying database with dummy data, but if that is the only way, so be it.

  • 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-07T12:51:18+00:00Added an answer on June 7, 2026 at 12:51 pm

    You don’t have to commit, but you need to flush the session to trigger execution of SQL statements:

    m_domainDao.saveOrUpdate(domain);    
    sessionFactory.getCurrentSession().flush();
    

    Then you can roll the transaction back if you don’t want to pollute the database.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I am writing an app with both english and french support. The app requests
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.