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

  • Home
  • SEARCH
  • 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 8685367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:33:10+00:00 2026-06-12T22:33:10+00:00

Is there a way to deterministically determine the database that is being used from

  • 0

Is there a way to deterministically determine the database that is being used from a user type ? My user type needs to pass different object to preparedStatement.setObject depending on the database (whether it is HSQL or Oracle). I was planning to use DataBaseMetaData from preparedStatement as

preparedStatement.getConnection().getMetaData().getDatabaseProductName()

but I’m not sure if there is a well defined set of strings that I can compare the above with to determine the database.

The larger problem that I’m trying to solve is , we use DATE column in Oracle, whereas hibernate maps JodaDateTime to TIMESTAMP(which is the only type that can hold date and time). So Oracle promotes DATE value in the DB to timestamp before performing date comparisons. This results in poor performance because database indexes are skipped. The option of changing column type from DATE to TIMESTAMP is ruled out because it requires more space and our application does not require precision beyond seconds. Thus I plan to write a userType that converts DateTime to oracle.sql.DATE and set the parameter in preparedStatement so that there is no index mismatch. (snippet shown below):

    public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException {
    if (value == null) {
        Hibernate.TIMESTAMP.nullSafeSet(preparedStatement, null, index);
    } else {
        preparedStatement.setObject(index, new oracle.sql.DATE(new Timestamp(((DateTime) value).getMillis())), Types.DATE);
    }
}

The problem with the above approach is that , If I use a different database for unit testing (HSQLDB), it won’t work because HSQLDialect does not understand “oracle.sql.DATE”. This is where I need to know the DB from userType and set different objects in preparedStatement.

So, I would like to know

  • If there is a better way to solve the DATE-TIMESTAMP mismatch problem
  • If not, how to identify DB from a usertype correctly.

Thanks.

  • 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-12T22:33:12+00:00Added an answer on June 12, 2026 at 10:33 pm

    Use Dialect.getDialect() to retrieve your current dialect. Check the instance type to know the database .e.g below:

           Dialect dialect= Dialect.getDialect();
           //<-- compare against the expected dailect classes
           if(dialect instanceof OracleDialect){  
               //your database is oracle
           }else if(dialect instanceof HSQLDialect){
            //<-- compare against the expected dailect classes
               //your database is HSQL
           }
    

    I am not very sure about your objective, but above should help you.

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

Sidebar

Related Questions

Is there way that I can read the file from remote server using fopen
Is there way in MySQL to create DATETIME from a given attribute of type
Is there way to add new method to List object over the object from
Is there way to get file from windows xp command prompt? I tried to
is there way how to get name ov event from Lambda expression like with
Is there any way I can set a formatter on models that will convert
Is there way for a class to 'remove' methods that it has inherited? E.g.
Is there way to associate a javascript function to a user control? Lets say
Is there way to show users that the website page started loading. My homepage
Is there way to print from Apple and Android mobile browsers via bluetooth. I

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.