Can you map embedable classes to an SqlType when implementing UserType

#1

Hi,

I know this approach will annoy some of you as it is very much not how the version annotation is meant to be used but I wondered if anyone could tell me if the below is possible anyway ?

I have implemented an override of UserType and UserVersionType for strings successfully but I wanted to do it for an embeddable class. Essentially this class has 3 ID fields that I’m hoping too use this mechanism to populate. So I have done this (everything works fine before I add my user type into the equation)…

//Standard hibernate code
Embeddable
public class TestType implements Serializable
{

Transient
public Class getUnderlyingClass() { return TestVersionType.class;}

Column(name="`id1`", nullable=false, length = 100)
private java.lang.String id1 = UUID.randomUUID().toString();

Column(name="`id2`", nullable=false, length = 100)
private java.lang.String id2;

Column(name="`id3`", nullable=false, length = 100)

public java.lang.String getId1()    {
    return id1;
}

public void setId1(java.lang.String value)    {
    this.id1= value;
}

public int compareTo(TestType b) {
	if (Id1.equals(b.Id1)) {
		return 0;
	} else {
		return -1;
	}
 }
}

Entity
Table (name="`hib_test`") 
public class HibernateTest implements Serializable {

private static final long serialVersionUID = 1L; 

Id
SequenceGenerator(name="seq-gen", sequenceName="seq", allocationSize=1)
GeneratedValue (strategy=GenerationType.SEQUENCE, generator="seq-gen")
Column(name="`id`", nullable=false)
private Long id;

Column(name="`NAME`", length=100)
private String name;

Type(type = "com.proto.usertypes.TestType")
Version
Embedded
    AttributeOverrides({
    AttributeOverride(name="id1", column=Column(name="`id1_in_testtype`"))
    ,AttributeOverride(name="id2", column=Column(name="`id2_in_testtype`"))
    ,AttributeOverride(name="id3", column=Column(name="`id3_in_testtype`"))
    })
private TestType testType;

public TestType getTestType()    {
        return testType;
    }
...
}

The problem is I’m not quite sure how to map TestObject to the 3 varchar database fields (id1, id2 and id3).

public class TestTypeUserType implements UserType {
protected TestType val;

public int[] sqlTypes() {
	return new int[] { Types.? };
}

public Class<TestType> returnedClass() {
	return TestType.class;
}
...
}

I’ve tried a number of Types but all of the return with somethign along the lines of
“No Dialect mapping for JDBC type: 2000”. I don’t think JAVA_OBJECT is correct because I’m not mapping to a specific database type but maybe I am wrong (it’s just that all the examples of this I’ve seen are against db types that don’t yet have a hibernate implementation rather than creating a dummy db type). STRUCT and ARRAY also failed.

Is there a mechanism to map the UserType to the 3 fields created by the embedded class ?

Thanks.