1

I have the following mapping for the birth date in the hbm.xml file

    <property name="birthDate" type="date">
    <column name="birth_date" length="4" />
    </property>>

The name/type of the column in the Postgresql database are: birth_date|date
Once in a while the date is inserted incorrectly – it is about 0.03% cases, the result is a strange date, i.e. a 2456 year What can be a reason? I suspect the column length of 4 in the hbm.xml file maybe not enough – not sure.

The hibernate version is 3.1

1
  • Probably you are passing a String that contains only a 2-digit year and the implicit conversion then gets confused. Commented Dec 6, 2011 at 8:24

2 Answers 2

1

If you are new to hibernate, Keep the declarations as simple as possible. So, if you want to add a Date Object in the mapping use the below code.

In the maaping file,

<property column="CREATED_DATE" name="createdDate" />

In java class,

java.lang.util.Date createdDate
//getters & setters

Once it is stable and working, you can start playing around with more options in the mapping.

Sign up to request clarification or add additional context in comments.

Comments

0

I was incorrect blaming the problem on Hibernate. The problem was in SimpleDateFormat. Someone before me specified a static class object of this class. In the multithreaded environment this resulted in incorrect Date formatting before using by Hibernate

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.