How can I persist a class with user defined-types attributes using
Hibernate?
For instance: I´d like Hibernate to store the result of getCNPJ().toString()
method into the CompanyTable at DBMS. However, it seems Hibernate serializes
the CNPJ object and stores it at DBMS.
----------------------------------------------------
package my.package.entity;
import my.package.types.Type_CNPJ;
public class CompanyEntity {
private Integer id;
public Integer getId() { return this.id; }
public setId( Integer newValue ) { this.id = newValue; }
private Type_CNPJ cnpj;
public Type_CNPJ getCNPJ() { return this.cnpj; }
public setCNPJ( Type_CNPJ newValue ) { this.CNPJ = newValue; }
}
----------------------------------------------------
CREATE TABLE [CompanyTable] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[CNPJ] [varchar] (14) NOT NULL
) ON [PRIMARY]
----------------------------------------------------
<hibernate-mapping>
<class name="my.package.entity.CompanyEntity " table="CompanyTable">
<id name="id" type="integer" column="ID">
<generator class="native"/>
</id>
<property name="cnpj" column="CNPJ" type="my.package.types.Type_CNPJ" />
</class>
</hibernate-mapping>