My custom type is (no default constructor!):
package com.XXX.common;
public class Email implements Serializable {
private String e;
public Email(String str) {
e = str;
}
}
My entity in Hibernate 3.5.6:
package com.XXX.persistence;
import com.XXX.common;
@Entity
@TypeDef(
name = "email",
defaultForType = Email.class,
typeClass = Email.class
)
public class User {
@Id private Integer id;
@Type(type = "email")
private Email email;
}
Hibernate says:
org.hibernate.MappingException: Could not determine type for:
com.XXX.common.Email, at table: user, for columns:
[org.hibernate.mapping.Column(email)]
What am I doing wrong?
A custom type must implement one of the interfaces from
org.hibernate.usertype(implementingUserTypewould be enough for your specific example), yourEmailclass is NOT a custom type. In other words, you’ll need to create someEmailTypeclass that Hibernate will use to persist a field or property of typeEmail.PS: There is IMO not much value at wrapping a
Stringwith a class but let’s say it was an example.References
Resources