Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since I could not find any solution on the web, we have implemented our own custom hibernate type, using an Integer type representing a YearMonth in the DB</p> <p>Here are the steps :</p> <p>1- Create the persistent class <code>PersistentYearMonth</code></p> <pre><code>public class PersistentYearMonth extends AbstractSingleColumnUserType&lt;YearMonth, Integer, IntegerColumnYearMonthMapper&gt; { private static final long serialVersionUID = -4204097887942539571L; } </code></pre> <p>2- Create the mapper <code>IntegerColumnYearMonthMapper</code></p> <pre><code>public class IntegerColumnYearMonthMapper extends AbstractIntegerColumnMapper&lt;YearMonth&gt; { private static final long serialVersionUID = -9060971007814071116L; @Override public YearMonth fromNonNullString(String s) { return YearMonth.parse(s, DateTimeFormat.forPattern("yyyyMM")); } @Override public YearMonth fromNonNullValue(Integer value) { return fromNonNullString(value.toString()); } @Override public String toNonNullString(YearMonth value) { return value.toString( DateTimeFormat.forPattern("yyyyMM")); } @Override public Integer toNonNullValue(YearMonth value) { return Integer.valueOf(toNonNullString(value)); } } </code></pre> <p>3- If you use XML hibernate mapping, register the custom type into the <code>hbm.xml</code> file when needed</p> <pre><code> &lt;property name="monthOfYear" type="org.jadira.usertype.dateandtime.joda.PersistentYearMonth" /&gt; </code></pre> <p>or if you are with annotations, register it as this:</p> <pre><code>@Type(type="org.jadira.usertype.dateandtime.joda.PersistentYearMonth") </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload