From: Gavin K. <Gav...@ex...> - 2002-12-16 22:24:35
|
Why don't you try stepping through code. Put a break point in=20 AbstractEntityPersister.setIdentifier() and see exactly what class of object is passed in. (This should definately all work as advertised.) > -----Original Message----- > From: phr...@im... [mailto:phr...@im...]=20 > Sent: Tuesday, 17 December 2002 7:14 AM > To: hib...@li... > Subject: RE: [Hibernate] custom identifier class >=20 >=20 > hi, >=20 > excuse my arrogance for re-posting this, but i haven't found=20 > a solution for the problem described below: >=20 > On Tue, 10 Dec 2002 12:34:56 -0500, phr...@im... said: > > hi, > >=20 > > On Tue, 10 Dec 2002 10:34:30 +1100, "Gavin King"=20 > > <Gav...@ex...> > > said: > > > Oh, so it isn't actually a composite key. I didn't understand=20 > > > properly then. Well, using a UserType is exactly the=20 > right approach.=20 > > > You would also need to implement IdentifierGenerator to generate=20 > > > instances of PrimaryKey (your implementation could just wrap up a=20 > > > built-in key generation strategy). This should work out=20 > perfectly -=20 > > > if you have any more problems let me know. > > >=20 > > > The mapping would be: > > >=20 > > > <id name=3D"key" type=3D"my.pkg.PrimaryKeyType"> > > > <generator class=3D"my.pkg.PrimaryKeyGenerator"/> > > > </id> > >=20 > > i created my own PK generator, but i'm still getting the same=20 > > exception i had before: > >=20 > > cirrus.hibernate.PropertyAccessException: IllegalArgumentException=20 > > occurred while calling setter of test.hibernate.Foo.pk at=20 > > cirrus.hibernate.helpers.ReflectHelper.set(ReflectHelper.java:190) > > at > >=20 > cirrus.hibernate.persister.AbstractEntityPersister.setIdentifier(Abstr > > actEntityPersister.java:281) > > at cirrus.hibernate.impl.SessionImpl.doSave(SessionImpl.java:528) > > at cirrus.hibernate.impl.SessionImpl.save(SessionImpl.java:483) > > at=20 > cirrus.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:919) > > at > >=20 > test.hibernate.ejb.HibTestSessionBean.saveFoo(HibTestSessionBe > an.java:53) > >=20 > > from Foo.hbm.xml: > >=20 > > <id type=3D"test.hibernate.MyPrimaryKeyType" name=3D"pk" column=3D"id"= > > length=3D"16" unsaved-value=3D"null"> > > <generator class=3D"test.hibernate.MySequencePKGenerator"> > > <param>MY_SEQ</param> > > </generator> > > </id> > >=20 > > Foo.java has: > >=20 > > public PrimaryKey getPk() > > public void setPk(PrimaryKey pk) > > (i tried adding setPk(Long), setPk(String), setPK(long) -=20 > that didnt > > chg the exception at all) > >=20 > >=20 > > My pk generator extends SequenceGenerator, and overrides=20 > one method as > > follows: > >=20 > > public Serializable generate(SessionImplementor session,=20 > Object obj) > > throws SQLException, HibernateException { > > return new PrimaryKey(=20 > String.valueOf(super.generate(session, obj)) ); > > } > >=20 > >=20 > > the implementation of my UserType is as follows: > >=20 > > private static final int[] TYPES =3D { Types.VARCHAR }; > >=20 > > public int[] sqlTypes() { > > return TYPES;=20 > > } > >=20 > > public Class returnedClass() { > > return PrimaryKey.class; > > } > >=20 > > public boolean equals(Object x, Object y) { > > if (x=3D=3Dy) return true; > > if (x=3D=3Dnull || y=3D=3Dnull) return false; > > return x.equals(y); > > } > >=20 > > public Object nullSafeGet(ResultSet rs, String[] names,=20 > Object owner) > > throws HibernateException, SQLException { > > String id =3D (String) Hibernate.STRING.nullSafeGet(rs, names[0]); > > return id=3D=3Dnull ? null : new PrimaryKey(id); > > } > >=20 > > public void nullSafeSet(PreparedStatement st, Object=20 > value, int index) > > throws HibernateException, SQLException { > > String id =3D (value=3D=3Dnull) ? null : ((PrimaryKey)value).getId(); > > Hibernate.STRING.nullSafeSet(st, id, index); > > } > >=20 > > public Object deepCopy(Object o) { > > if (o=3D=3Dnull) return null; > > return new PrimaryKey( (PrimaryKey)o ); > > } > >=20 > > public boolean isMutable() { > > return false; > > } > >=20 > >=20 > > any help would be appreciated :) > >=20 > > viktor > > -- > > =20 > > phr...@im... > >=20 > > -- > > http://fastmail.fm - Does exactly what it says on the tin > --=20 > =20 > phr...@im... >=20 > --=20 > http://fastmail.fm - Does exactly what it says on the tin >=20 >=20 > ------------------------------------------------------- > This sf.net email is sponsored by: > With Great Power, Comes Great Responsibility=20 > Learn to use your power at OSDN's High Performance Computing=20 > Channel http://hpc.devchannel.org/=20 > _______________________________________________ > hibernate-devel mailing list hib...@li... > https://lists.sourceforge.net/lists/listinfo/hibernate-devel >=20 ********** CAUTION - Disclaimer ********** This message may contain privileged and confidential information. If you are not the intended recipient of this message (or responsible for delivery of the message to such person) you are hereby notified that any use, dissemination, distribution or reproduction of this message is prohibited. If you have received this message in error, you should destroy it and kindly notify the sender by reply e-mail. Please advise immediately if you or your employer do not consent to Internet e-mail for messages of this kind. Opinions, conclusions and other information in this message that do not relate to the official business of Expert Information Services Pty Ltd ("The Company") shall be understood as neither given nor endorsed by it. The Company advises that this e-mail and any attached files should be scanned to detect viruses. The Company accepts no liability for loss or damage (whether caused by negligence or not) resulting from the use of any attached files. **EIS******** End of Disclaimer ********** |