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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:28:21+00:00 2026-06-14T23:28:21+00:00

Im new in hibernate I write a small application with hibernate and struts2 my

  • 0

Im new in hibernate

I write a small application with hibernate and struts2

my problem is

when i update datetime my time will be 00:00:00 or 12:00:00 it not correct to what i choose like 04:50:10 or 18:20:11

I try many times but it till not work

In my form i have a field is string and then i convert it into date and then update it with hibernate

my convert code

public Date convertStringToDate(String str) {
        Date date = null;
        SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss a");
        try {
            date = formatter.parse(str);
        } catch (ParseException ex) {
            Logger.getLogger(NewsAdminAction.class.getName()).log(Level.SEVERE, null, ex);
        }
        return date;
    }

    public String convertDateToString(Date date) {
        SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss a");
        String str = formatter.format(date);
        return str;
    }

my update code hibernate

//create session begin transaction

    String sqlNoThumb = "UPDATE News set title = :title, info = :info, publicdate = :publicdate, active = :active, titleviet = :titleviet where idnews = :idnews";

    Query query = session.createQuery(sqlNoThumb);
                    query.setString("title", news.getTitle());
                    query.setString("info", news.getInfo());
                    query.setDate("publicdate", news.getPublicdate());
                    query.setInteger("active", news.getActive());
                    query.setString("titleviet", news.getTitleviet());
                    query.setInteger("idnews", news.getIdnews());
                    result = query.executeUpdate();
  • 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-14T23:28:23+00:00Added an answer on June 14, 2026 at 11:28 pm

    You need to use a java.sql.Timestamp, not a java.sql.Date

    From the JavaDocs:

    To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be ‘normalized’ by setting the hours, minutes, seconds, and milliseconds to zero

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

Sidebar

Related Questions

I am trying to get hibernate to write new objects each time I do
I'm having a small problem with my insert statements in Spring-data/jpa/hibernate/mysql/junit application. I created
I am new to the Hibernate and HQL. I want to write an update
I am new to Hibernate. I have an exception while running an Hibernate-based application.
I'm quite new to hibernate and have stumbled on this problem, which I can't
I'm new to Hibernate and I'm struggling with problem: I have 3 tables and
I'm using hibernate search 3.4, and I'm running in to a small problem. I
I have to use JDBC to write to a database (hibernate/ibatis is not an
I'm very new to JBoss, EJB3, hibernate, and MySQL. I am trying to write
I'm trying to write a method that will return a Hibernate object based on

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.