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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:20:09+00:00 2026-05-30T20:20:09+00:00

I saw a tutorial in the web showing you can do something like this

  • 0

I saw a tutorial in the web showing you can do something like this for deletes and updates in Hibernate:

Query query = session.createQuery("delete Stock where stockCode = :stockCode");
query.setParameter("stockCode", "7277");
int result = query.executeUpdate();

In the same tutorial I came across this code for insertion:

Query query = session.createQuery("insert into Stock(stock_code, stock_name)" +
            "select stock_code, stock_name from backup_stock");
int result = query.executeUpdate();

My question is, is it possible to do something like the delete example from the tutorial, but for the insertion method instead, by using setParameter? I tried something like this and got an error:

Query q = session.createQuery("insert into test(:testname)");
q.setParameter("testname", "tester");

The error was regarding properties. One of my reason to use the above code is because of the

 int result =  query.executeUpdate()

which can return a result to verify whether I successfully inserted via the SQL command or not.

  • 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-30T20:20:11+00:00Added an answer on May 30, 2026 at 8:20 pm

    First thing :

    setParameter

    has been create for parameters in HQL queries, not field name.

    Second thing :

    Your request : insert into test(:testname) seems incomplete, it should be something like insert into [TABLE_NAME]([FIELD_NAME],...) values ([VALUE],...) and In that case you should use SQL queries with :

    createSQLQueries

    See: http://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/Session.html#createSQLQuery(java.lang.String)

    . Why do you need to make your query so dynamic ?

    And an insert into the database would be better with a save :

    session.save(youHibernateObject);
    

    with youHibernateObject an object mapped with hibernate model mapping schemas. Good luck.

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

Sidebar

Related Questions

I am following this tutorial from MSDN. There's something I saw in the code
I saw this same question for VIM and it has been something that I
I saw this question asked about C# I would like an answer for PHP.
In one Android Tutorial I saw the usage of this function. There he uses
I saw that you can embed meta-data into images very much like you can
Here is the tutorial which i saw: http://papermashup.com/simple-jquery-tabs/ As you can see the Tabs
Hi I'm new to Visual Studio.NET.I saw a tutorial but I can't see any
I am reading the Google Go tutorial and saw this in the constants section:
While reading tutorial for wxWiidgets I saw this Tutorial where author has created 2
I was reading the dojo query tutorial and saw // retrieve an array of

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.