Hibernate version: 3.2.5
Full stack trace of any exception that occurs: N/A
Name and version of the database you are using: MySQL Ver. 14.12 Distrib 5.0.15 for Win 32
Hi Everyone,
I seem to be having an issue using a custom UserType I created to handle java.net.URI objects. Prior to implementing a UserType the value is stored in the database as a MySQL type VarBinary. I want this value to be stored as a VarChar; So, I attempted to create a UserType to resolve my need. After creating a custom UserType to store the URI object as a Hibernate.STRING and retrieve a Hibernate.STRING as a java.net.URI object, the database is still populated with a datatype of VarBinary. I debugged the code and noticed that my custom UserType's nullSafeSet is never called (at this time I am just trying to populate the database, no retrieval is being done yet.) I've been running the application and debugging the application within my Eclipse IDE.
Here is the mapping, and class:
Mapping File Snippet:
Code:
<class entity-name="DocumentData" table="tbl_documents">
<id name="executionId" type="integer" />
<component name="doc" class="com.coname.Document" />
</class>
<class name="com.coname.Document" table="tbs_documents">
<id name="docId">
<generator class="native" />
</id>
<property name="uri" type="com.coname.persistence.hibernate.usertypes.URIUserType" />
<property name="executionId"/>
</class>
Java Class UserType Snippet:Code:
public class URIUserType implements org.hibernate.usertype.UserType{
public Object nullSafeGet(ResultSet rs, String[] uris, Object owner) throws HibernateException, SQLException{
String uriString = (String) Hibernate.STRING.nullSafeGet(rs, uris[0]);
if(uriString == null){
return null;
}
try{
return new java.net.URI(uriString);
}
catch...
}
public void nullSafeSet(PreparedStatement stmt, Object value, int index) throws HibernateException, SQLException{
String uriToString = null;
if(value != null){
uriToString = ((java.net.URI) value).toString();
Hibernate.STRING.nullSafeSet(stmt, uriToString, index);
}
}
...Other implemented methods required by org.hibernate.usertype.UserType
}
Calling Hibernate Java Snippet:Code:
HashMap<String, Object> docMap = new HashMap<String, Object>();
docMap.put("executionId", workflowExecutionId);//workflowExecutionId is a variable set by Hibernate in a previous step.
docMap.put("doc", doc);//doc is a Document object that has been declared and populated.
session = sessionFactory.getCurrentSession();
session.beginTransaction();
session.save("DocumentData", docMap);
//I've also tried to call session.flush() prior to calling commit.
session.getTransaction().commit();
My database is getting populated as expected with all of the other values, it is just the URI that I am attempting to save never goes through the URIUserType that I created and is saved in what I presume is the default VarBinary data type. I've also gone as far as to create a CompositeUserType doing the same thing with no success either. Any guidance would be greatly appreciated. Please let me know if I've left out any crucial or pertinent information. Thanks for your time.