Hibernate, one UserType with different number of columns

I have a class

class DateOptTimeType implements org.hibernate.usertype.UserType

which works with two columns

@org.hibernate.annotations.Type(type = "com.mmyPack.DateOptTimeType")
@org.hibernate.annotations.Columns(columns = {
                 @javax.persistence.Column(name = "DATE1"),
                 @javax.persistence.Column(name = "FLAG")
                                   }) protected DateOptTime dateOfDeath;

Can I do this, this class will work with 1 column (with 1 column and two columns), for example

                    @javax.persistence.Column(name = "DATE1"),
                    protected DateOptTime dateOfDeath;
+5
source share
1 answer

You need 2 UserTypes because UserType returns the number of columns needed in getSqlTypes()

+4
source

All Articles