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

The Archive Base Latest Questions

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

I am using Hibernate to access my database. I would like to delete a

  • 0

I am using Hibernate to access my database. I would like to delete a set of fields on function of a criteria. My database is PostgreSQL and my Java code is:

public void deleteAttr(String parameter){
    Configuration cfg = new Configuration();
    cfg.configure(resource.getString("hibernate_config_file"));
    SessionFactory sessionFactory = cfg.buildSessionFactory();
    session = sessionFactory.openSession(); 
    Transaction tx = session.beginTransaction();
    tx.begin();
    String sql = "delete from attribute where timestamp > to_date('"+parameter+"','YYYY-MM-DD')"
    session.createSQLQuery(sql);
    tx.commit();
}

The method runs, but it doesn’t delete data from database. I have also checked the sql sentence in PgAdmin and it works, but not in code. Why? Does someone help me?

Thanks in advance!

  • 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-23T16:20:31+00:00Added an answer on May 23, 2026 at 4:20 pm

    It’s because you’re creating a query, but you don’t execute it:

    String sql = "delete from attribute where timestamp > to_date('"+parameter+"','YYYY-MM-DD')"
    Query query = session.createSQLQuery(sql);
    query.executeUpdate();
    

    You should really use bound named parameters rather than string concatenation to pass parameters in your query: it’s usually more efficient, it’ much more robust, but above all, it doesn’t open the door to SQL injection attacks.

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

Sidebar

Related Questions

I am using Hibernate in a Java application to access my Database and it
I'm using Hibernate for ORM of my Java app to an Oracle database (not
There's an enterprise application using Java + Hibernate + PostgreSQL. Hibernate is configured via
I'm using Fluent NHibernate auto mapping. I need to access more than one database
I needed to create an application using Struts2 as MVC,Hibernate for data access and
my problem is that, i want to save class object java.lang.reflect.Field into database using
I am using Hibernate in an Eclipse RAP application. I have database tables mapped
I'm using Maven 2 and Hibernate for a Java web app. I have a
I am using NHibernate to as the Data Access layer for my ASP.NET MVC
Using hibernate, how can I persist a class with a List<String> field? Consider the

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.