Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate, one UserType with different number of columns

Tags:

java

hibernate

I have class

class DateOptTimeType implements org.hibernate.usertype.UserType

that 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, that class will work with 1 column too (with 1 column and with two columns), like

                    @javax.persistence.Column(name = "DATE1"),
                    protected DateOptTime dateOfDeath;
like image 778
Ilya Avatar asked Oct 09 '22 23:10

Ilya


1 Answers

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

like image 133
Firo Avatar answered Oct 12 '22 13:10

Firo