hi,
On Tue, 10 Dec 2002 10:34:30 +1100, "Gavin King" <[EMAIL PROTECTED]>
said:
> Oh, so it isn't actually a composite key. I didn't understand
> properly then. Well, using a UserType is exactly the right
> approach. You would also need to implement IdentifierGenerator
> to generate instances of PrimaryKey (your implementation could
> just wrap up a built-in key generation strategy). This should
> work out perfectly - if you have any more problems let me know.
>
> The mapping would be:
>
> <id name="key" type="my.pkg.PrimaryKeyType">
> <generator class="my.pkg.PrimaryKeyGenerator"/>
> </id>
i created my own PK generator, but i'm still getting the same exception i
had before:
cirrus.hibernate.PropertyAccessException: IllegalArgumentException
occurred while calling setter of test.hibernate.Foo.pk
at cirrus.hibernate.helpers.ReflectHelper.set(ReflectHelper.java:190)
at
cirrus.hibernate.persister.AbstractEntityPersister.setIdentifier(AbstractEntityPersister.java:281)
at cirrus.hibernate.impl.SessionImpl.doSave(SessionImpl.java:528)
at cirrus.hibernate.impl.SessionImpl.save(SessionImpl.java:483)
at cirrus.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:919)
at
test.hibernate.ejb.HibTestSessionBean.saveFoo(HibTestSessionBean.java:53)
from Foo.hbm.xml:
<id type="test.hibernate.MyPrimaryKeyType" name="pk" column="id"
length="16" unsaved-value="null">
<generator class="test.hibernate.MySequencePKGenerator">
<param>MY_SEQ</param>
</generator>
</id>
Foo.java has:
public PrimaryKey getPk()
public void setPk(PrimaryKey pk)
(i tried adding setPk(Long), setPk(String), setPK(long) - that didnt
chg the exception at all)
My pk generator extends SequenceGenerator, and overrides one method as
follows:
public Serializable generate(SessionImplementor session, Object obj)
throws SQLException, HibernateException {
return new PrimaryKey( String.valueOf(super.generate(session, obj)) );
}
the implementation of my UserType is as follows:
private static final int[] TYPES = { Types.VARCHAR };
public int[] sqlTypes() {
return TYPES;
}
public Class returnedClass() {
return PrimaryKey.class;
}
public boolean equals(Object x, Object y) {
if (x==y) return true;
if (x==null || y==null) return false;
return x.equals(y);
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
throws HibernateException, SQLException {
String id = (String) Hibernate.STRING.nullSafeGet(rs, names[0]);
return id==null ? null : new PrimaryKey(id);
}
public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException {
String id = (value==null) ? null : ((PrimaryKey)value).getId();
Hibernate.STRING.nullSafeSet(st, id, index);
}
public Object deepCopy(Object o) {
if (o==null) return null;
return new PrimaryKey( (PrimaryKey)o );
}
public boolean isMutable() {
return false;
}
any help would be appreciated :)
viktor
--
[EMAIL PROTECTED]
--
http://fastmail.fm - Does exactly what it says on the tin
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel