RE: [Hibernate] custom identifier class
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:
>
>
>
>
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:
MY_SEQ
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
Re: [Hibernate] Ohhh this looks cool
hi, On Tue, 22 Oct 2002 04:34:54 +1000, "Gavin King" <[EMAIL PROTECTED]> said: > Can we use this to do lazy initialization of objects without the need for > proxy interfaces? wouldn't you have to do this at class loading time then? that is: how would you make your generated look like the original one? with interfaces it's doable at runtime, as long as the client refers to the generated class through the interface... viktor -- [EMAIL PROTECTED] -- http://fastmail.fm - Access your email with Outlook or over the web --- This sf.net emial is sponsored by: Influence the future of Java(TM) technology. Join the Java Community Process(SM) (JCP(SM)) program now. http://ad.doubleclick.net/clk;4699841;7576298;k?http://www.sun.com/javavote ___ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
[Hibernate] custom identifier class
hi, how can one use an alternative class for primary keys (eg. MyPrimaryKey instead of a string)? I tried using a UserType for this purpose, but reflection fails with an IllegalArgumentException in AbstractEntityPersiser.setIdentifier. best regards, viktor -- [EMAIL PROTECTED] -- http://fastmail.fm - Accessible with your email software or over the web --- 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
Re: [Hibernate-devel] Volunteers? [alter schema]
This mail is probably spam. The original message has been attached along with this report, so you can recognize or block similar unwanted mail in future. See http://spamassassin.org/tag/ for more details. Content preview: hi, On Tue, 20 Aug 2002 17:09:23 +0200, "Christoph Sturm" <[EMAIL PROTECTED]> said: > - Original Message - > From: > > > This would be very cool. How do you propose to implement it? Diffing two > > "create table" statements? Diffing two mapping documents? Diffing against > > JDBC metadata? > > I was thinking about diffing against jdbc metadata. What I had in mind was > an automatic check of the database metadata when hibernate starts up, and > automatic execution of ddf statements that add missing columns and tables. [...] Content analysis details: (8.10 points, 8 required) NO_REAL_NAME (3.0 points) From: does not include a real name X_MAILING_LIST (0.0 points) Has a X-Mailing-List header FOR_FREE (6.0 points) BODY: No such thing as a free lunch (1) KNOWN_MAILING_LIST (-0.9 points) Email came from some known mailing list software --- Begin Message --- hi, On Tue, 20 Aug 2002 17:09:23 +0200, "Christoph Sturm" <[EMAIL PROTECTED]> said: > - Original Message - > From: > > > This would be very cool. How do you propose to implement it? Diffing two > > "create table" statements? Diffing two mapping documents? Diffing against > > JDBC metadata? > > I was thinking about diffing against jdbc metadata. What I had in mind was > an automatic check of the database metadata when hibernate starts up, and > automatic execution of ddf statements that add missing columns and tables. even this poses some problems, eg. when you're trying to add a NOT NULL column... also, renaming a column would not be recognized... so i think the closest you can get is a schema comparison, and a default alter script, which you have to tweak manually. still comes handy though, but has not much to do with hibernate itself i guess :) viktor -- [EMAIL PROTECTED] -- http://fastmail.fm Quick as a click --- This sf.net email is sponsored by: OSDN - Tired of that same old cell phone? Get a new here for FREE! https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 ___ Hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel --- End Message ---
RE: [Hibernate] custom identifier class
hi, it seems to be some sort of class-loading issue - the PrimaryKey class that the generator returns, and the one that the bean uses seems to have been loaded by a different classloader, so even though they are the same class, they are not compatible. have someone encountered the same issue? is there a way i can make hibernate use the same classloader? best regards, viktor On Tue, 17 Dec 2002 09:24:23 +1100, "Gavin King" <[EMAIL PROTECTED]> said: > Why don't you try stepping through code. Put a break point in > > AbstractEntityPersister.setIdentifier() > > and see exactly what class of object is passed in. (This should > definately all work as advertised.) > > > > > > > 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(Abstr > > > actEntityPersister.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(HibTestSessionBe > > an.java:53) > > > > -- [EMAIL PROTECTED] -- http://fastmail.fm - Consolidate POP email and Hotmail in one place --- This SF.NET email is sponsored by: Order your Holiday Geek Presents Now! Green Lasers, Hip Geek T-Shirts, Remote Control Tanks, Caffeinated Soap, MP3 Players, XBox Games, Flying Saucers, WebCams, Smart Putty. T H I N K G E E K . C O M http://www.thinkgeek.com/sf/ ___ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
[Hibernate] Enum
hi, would it be feasible to migrate to using the Enum classes from jakarta (lang commons)? in the long run, i think it would greatly reduce the need to create adapter classes for these... best regards, viktor -- [EMAIL PROTECTED] -- http://fastmail.fm - Email service worth paying for. Try it for free --- 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
RE: [Hibernate] custom identifier class
hi, On Tue, 10 Dec 2002 09:10:09 +1100, "Gavin King" <[EMAIL PROTECTED]> said: > This has been requested once before, and it would be very > trivial to add support for a subelement of > . But theres always something very fishy > about using a generated (ie. synthetic) composite id. It > really makes no sense. It never even makes sense to have a > single be generated > > I can't imagine why you would want it i'm trying to port some legacy code over to hibernate. the code relies on a PrimaryKey class for identifying objects. this is not a composite key, so automatic generation totally makes sense (it really just encapsulates a String id property). changing this all over the place would be somewhat painful, that's why i was trying to work around it within the boundaries of Hibernate. i would like to know what sort of direction would you recommend, eg - replace the PrimaryKey class with String everywhere (-> pain) - extend hibernate along the lines you mentioned (sounds good to me, but i need further directions) - can i just directly use the guts of hibernate to get a new ID? - map it some other way (i tried a UserType, didn't really work out) thanks, viktor -- [EMAIL PROTECTED] -- http://fastmail.fm - Faster than the air-speed velocity of an unladen european swallow --- 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
Re: [Hibernate] custom identifier class
hi, On 08 Dec 2002 10:25:30 -0500, "Chris Winters" <[EMAIL PROTECTED]> said: > On Sat, 2002-12-07 at 19:12, [EMAIL PROTECTED] wrote: > > how can one use an alternative class for primary keys (eg. MyPrimaryKey > > instead of a string)? I tried using a UserType for this purpose, but > > reflection fails with an IllegalArgumentException in > > AbstractEntityPersiser.setIdentifier. > > Lookup the 'composite-id' property in the docs. Here's an example for > one of my objects: i considered this approach (even though my pk class is not a composite). however, the problem is that i can no longer rely on hibernate to generate the PKs for me. that's why i was trying to use a UserType. so, is there a way to reuse the functionality in the hibernate PK generators when using a composite-id? thanks, viktor -- [EMAIL PROTECTED] -- http://fastmail.fm - IMAP accessible web-mail --- 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
RE: [Hibernate] custom identifier class
hi,
excuse my arrogance for re-posting this, but i haven't found a solution
for the problem described below:
On Tue, 10 Dec 2002 12:34:56 -0500, [EMAIL PROTECTED] said:
> 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:
> >
> >
> >
> >
>
> 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:
>
> length="16" unsaved-value="null">
>
> MY_SEQ
>
>
>
> 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
--
[EMAIL PROTECTED]
--
http://fastmail.fm - Does exactly what it says on the tin
---
This sf.net email is sponsored by:
With Great Power, Comes Great Responsibility
Learn to use your power at OSDN's High Performance Computing Channel
http://hpc.devchannel.org/
___
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel
