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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:17:38+00:00 2026-05-22T23:17:38+00:00

I have a problem with saving a huge amount of records to database using

  • 0

I have a problem with saving a huge amount of records to database using CFWheels. Here is an example:

<cfloop from="1" to="10000" index="i">
 <cfset var newUser = model("user").new()>
 <cfset newUser.name = "Test"&i>
 <cfset newUser.save()>
</cfloop>

This causes java.lang.OutOfMemoryError

Please help me how to solve this problem.

  • 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-22T23:17:38+00:00Added an answer on May 22, 2026 at 11:17 pm

    There are a couple fairly inefficient things going on here. First, it’s generating 1,000 user objects, which isn’t really a good idea to do in a single request in ColdFusion. Second, it’s running 1,000 database queries, which isn’t really a good idea to do in any programming language.

    I would stop using model objects for a case like this and figure out how to condense the logic into a single database query. The ORM stuff in Wheels is generally very useful, but it has its limits in situations like this one.

    For example, if you’re using SQL Server 2008, you can do this inside your user model to keep everything under a single call to cfquery:

    <cffunction name="batchCreate">
        <cfquery datasource="#get('dataSourceName')#">
            INSERT INTO
                #this.tableName()# (#this.columnNameForProperty("name")#)
            VALUES
                <cfloop from="1" to="10000" index="i">
                    (<cfqueryparam cfsqltype="cf_sql_varchar" value="Test#i#">)
                    <cfif i lt 10000>,</cfif>
                </cfloop>
        </cfquery>
    </cffunction>
    

    Of course, the query will look different if you’re using MySQL or another database engine.

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

Sidebar

Related Questions

I have a problem with saving data from Ext.data.DirectStore to server Here is my
We have a weird intermittent problem with saving from Word 2007 to our SharePoint
We have a problem with the Euro character when saving and retrieving it from
I have problem with saving object to database with NHibernate. Program throws no error
I have a problem with saving the £ symbol to a mysql database. I
I have a problem using the Java search function in Eclipse on a particular
am having problem in Saving some data in my Java code. I have like
I have a problem using compass-style remotley over ssh and my favorite text-editor textmate.
I have a problem with saving 4000 characters to varchar2(4000) oracle 10g column it
I am using Spring 3.0 with Hibernate and PostgreSQL and I have following problem:

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.