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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:09:41+00:00 2026-05-14T00:09:41+00:00

We have some columns with data that must always be in uppercase to ensure

  • 0

We have some columns with data that must always be in uppercase to ensure uniqueness. I was wondering if hibernate can force all such columns to uppercase via some configuration file change?

We actually use a custom UserType for encrypting/decrypting column data for some other table, but I figured that would be overkill just to uppercase everything…

Alternatively, I was thinking about modifying the models such that all getters/setters will uppercase any string coming and going.

The worst(?) case scenario is to modify the Oracle column constraint to ignore case while checking uniqueness.

Any thoughts?

  • 1 1 Answer
  • 1 View
  • 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-14T00:09:41+00:00Added an answer on May 14, 2026 at 12:09 am

    I decided to implement a UserType…it is as close to a hibernate configuration as I can get…here’s the code…

    package model;
    
    import java.io.Serializable;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Types;
    
    import org.apache.commons.lang.builder.EqualsBuilder;
    import org.apache.commons.lang.builder.HashCodeBuilder;
    import org.hibernate.Hibernate;
    import org.hibernate.HibernateException;
    import org.hibernate.usertype.UserType;
    
    public class UpperCaseUserType implements UserType {
        private static final int[] TYPES = {Types.VARCHAR};
    
    public int[] sqlTypes() {
            return TYPES;
    }
    
    public Class returnedClass() {
            return String.class;
    }
    
    public boolean equals(Object x, Object y) throws HibernateException {
            if (x == y) {
                return true;
            }
            if (null == x || null == y) {
                return false;
            }
            return new EqualsBuilder().append(x, y).isEquals();
    }
    
    public int hashCode(Object o) throws HibernateException {
            return new HashCodeBuilder().append(o).toHashCode();
    }
    
    public Object nullSafeGet(ResultSet resultSet, String[] strings, Object object) throws HibernateException, SQLException {
            return ((String) Hibernate.STRING.nullSafeGet(resultSet, strings[0])).toUpperCase();
    }
    
    public void nullSafeSet(PreparedStatement preparedStatement, Object object, int i) throws HibernateException, SQLException {
            String string = ((String) object).toUpperCase();
            Hibernate.STRING.nullSafeSet(preparedStatement, string, i);
    }
    
    public Object deepCopy(Object o) throws HibernateException {
            if (null == o) {
                return null;
            }
            return new String(o.toString());
    }
    
    public boolean isMutable() {
            return false;
    }
    
    public Serializable disassemble(Object o) throws HibernateException {
            return (String) o;
    }
    
    public Object assemble(Serializable serializable, Object o) throws HibernateException {
            return serializable;
    }
    
    public Object replace(Object o, Object arg1, Object arg2) throws HibernateException {
            return o;
    }
    }
    

    Consider this property element

    <property name="serialNumber" type="model.UpperCaseUserType">
        <column name="SERIAL_NUMBER" length="20" not-null="true" unique="true" />
    </property>
    

    So the reasoning…As hibernate inserts the data, this type will convert the string to uppercase. As hibernate selects data, the same thing happens. The advantage this class has over just changing the bean’s get/set to uppercase everything is when I use a Criteria to select on serialNumber. Hibernate will also uppercase my parameter as it will cast/apply the same type as defined in the table configuration.

    Therefore, I don’t need to remember to manually uppercase all of my search criteria for serial numbers…hibernate takes care of that for me…that’s exactly what I’m trying to achieve here!

    I have a JUnit that demonstrates all of this stuff, but I think my answer is way too big as it is…

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

Sidebar

Related Questions

I have some data that I am displaying in 3 column format, of the
I have some data that looks something like this... +----------+----------+----------+ | Column 1 |
I have to sort out my data by some column, such that some specific
I have some data I am querying. The table is composed of two columns
I have a data frame where some of the columns contain NA values. How
I have a data frame with an id column and some (potentially many) columns
I have some vectors of experimental data that I need to massage, for example:
I have some existing code that retrieves data from a database using ADO.NET that
I have some data in an SQL table with an XML datatype column where
I need to get some data from a column. For example I have data

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.