我在java / hibernate应用程序中有一个嵌入式类,我想将其映射为3个数据库字段作为Type(以便可以将其用作CustomVersionType)。目前,我遇到的错误是
org.hibernate.MappingException:属性映射的编号错误 列:com.imsproto.model.RuleOfEngagementCI.contextIdentifier类型: com.imsproto.usertypes.ContextualisedIdentifierVersionType
说实话,我不确定映射是否可以解决问题,但我想尝试。据我所知,其中扩展了方言并添加自定义映射的场景是针对数据库中实际上存在未映射类型的场景(我见过的示例可能已经过时,但包含UUID和json字段)。在这种情况下,我要针对3个字段映射一些复合类型。这是桌子的结构...
//Standard hibernate code
@Embeddable
public class TestType implements Serializable
{
@Transient
public Class getUnderlyingClass() { return TestType.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;
}
...
}
我要做的是将TestType映射为Type,以便将其视为复合数据类型。添加后,可以通过Java.sql.Types枚举访问此类型。这可能吗?还是我在抓稻草?