Skip to main content

Posts

Showing posts from December, 2013

Hibernate And Mapping enum to customized values

With Hibernate, enums can be easily mapped either by enum item name or the position of each item but what if you want to map it to a customized value? In my case, we have so many one-character long columns in our tables, representing flags, statuses etc. We have heaps of them. Writing UserTypes for each enum field is very boring and nasty job. As every where you see in internet, you need to keep a Map for each user-type in order to map those values to enum elements. So to avoid this, I ended up with something more clean, easy and more generic. Now imagine you have following enum: public enum PaymentFrequencyEnum { WEEKLY("WK"), FORTNIGHTLY("FN"), MONTHLY("MT"), QUARTERLY("QL"), YEARLY("YL"); private String value;     private PaymentFrequency(String value) { this.value = value; } } I've chosen two-letter code as value so that you understand m

Migrating from OJB to Hibernate

Okay now I have to migrate a dozen of domain objects from OJB to Hibernate entities and since we still have to use hbm files as opposed to Annotation, this is no enjoying task... I found this XML Stylesheet from this website below but had to make some changes in order to get it working... so I thought it may help someone: Download XSL file here Original file can be found here but so far at this time which is 16th of December 2013 and 6:37pm, it's not working properly :) martindavidsson blog