[Hibernate] wrong behavior in the net.sf.hibernate.collection.Set.remove()
I had an object a of type A retieved from hibernate Set. I did some modification to the a. During this process, its hashCode changed. Then I would like to remove it from the Set. I removed it like this net.sf.hibernate.collection.Set.remove(A). The hibernate Set can not find and remove the Object a! If I modify the type A so that its hashCode returns a constant value. No problem, hibernate Set can find and remove the Object. Below is the Set.remove() specification from Jdk 1.4. --- Removes the specified element from this set if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if the set contains such an element. Returns true if the set contained the specified element (or equivalently, if the set changed as a result of the call). (The set will not contain the specified element once the call returns.) Notice that this spec never mentions anything about the hashCode. Moreover an object is only required to have a constant hashCode value provided no information used in equals comparisons on the object is modified. In hibernate current implementation, if a object is retrieved from Set and its hashCode is changed, there is no way to remove it from set. Any thoughts on this? Help is appreciated. jason __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com --- This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa0013ave/direct;at.aspnet_072303_01/01 ___ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
[Hibernate] What does this exception mean?
Hi, all Caused by: net.sf.hibernate.HibernateException: Flush during cascade is dangerous - this might occur if an object was deleted and then re-saved by cascade Any hint what might cause this exception? Thanks jason __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com --- This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa0013ave/direct;at.aspnet_072303_01/01 ___ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
Re: [Hibernate] Saving collections...
--- [EMAIL PROTECTED] wrote: > > You need to learn about the mysteries of the > unsaved-value > attribute :) > > Hibernate looks at the id value to determine if an > object > discovered by cascade is "new" or not. So, if you > have an > object with a Long identifier, set > unsaved-value="null". I noticed that you use "Long" class as identified. Can I use primitive type long as identifier and use "0" as unsaved-value? > Note that another approach is to save() the Item > explicitly, > before flushing. > > > > > > > > "Matt Dowell" > > > <[EMAIL PROTECTED]> >To: > <[EMAIL PROTECTED]> > > Sent by: >cc: > > > [EMAIL PROTECTED] Subject: > [Hibernate] Saving collections... > > eforge.net > > > > > > > > > 30/01/03 09:56 AM > > > > > > > > > > > > > Easy question, I think. > > I am trying something like this: > > Product p = new Product(); > p.setName("blah"); > > ProductLineItem item = new ProductLineItem(); > item.setName("blah line item"); > > > // Add a line item to the product > p.addLineItem(item); > > > Session.save(p); > > > and it is inserting the Product, and trying to > update the LineItem. > Can it insert the product, then insert the LineItem > or is this not > supported? > > Thanks, > > Matt Dowell > Notiva Corp. > > > --- > This SF.NET email is sponsored by: > SourceForge Enterprise Edition + IBM + LinuxWorld = > Something 2 See! > http://www.vasoftware.com > ___ > hibernate-devel mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/hibernate-devel > > > > > ** > Any personal or sensitive information contained in > this email and > attachments must be handled in accordance with the > Victorian Information > Privacy Act 2000, the Health Records Act 2001 or the > Privacy Act 1988 > (Commonwealth), as applicable. > > This email, including all attachments, is > confidential. If you are not the > intended recipient, you must not disclose, > distribute, copy or use the > information contained in this email or attachments. > Any confidentiality or > privilege is not waived or lost because this email > has been sent to you in > error. If you have received it in error, please let > us know by reply > email, delete it from your system and destroy any > copies. > ** > > > > > > --- > This SF.NET email is sponsored by: > SourceForge Enterprise Edition + IBM + LinuxWorld = > Something 2 See! > http://www.vasoftware.com > ___ > hibernate-devel mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/hibernate-devel __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com --- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com ___ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
Re: [Hibernate] what does "readonly=true" mean in a bidirectional association?
--- [EMAIL PROTECTED] wrote: > > >Here the children set in the Parent object is > >readonly. Does it mean any modification to any > "Child > >element" in the Children set will not be persisted > to > >database( an violation of usual persistence by > >reachability)? In > > No, it is nothing to do with cascades. > > >this sense, the "readonly" applies > >to the set element. Or Does it mean any addition > and > >removal from the Children set will not be persisted > to > >the database? In this sense, the "readonly" applies > to > >the set itself. > > Yes, thats exactly what it means. suppose, I want to add one child element to the children set. I have to do this 1. add the child element to the children set. 2. save the child explicitly by calling Session.save(child). Is it right? By specifying "readonly", in the code I have to remember which set is readonly and I have to handle it differently from set that is not readonly. Is this right ? > >If we have a bidirectinoal association, but I do > not > >specify the readonly for one end of the > association. > >What can be resulted from it? > > Extra unnecessary SQL statements will be executed. > > >Also why can the "readonly" attribute not be > specified > >for element? > > I was being ultra-conservative. This is supported in > hibernate-mapping-2.0.dtd (ie. Hibernate2). You can > even allow it in 1.2, simply by editing the DTD. > > (Note that this is renamed "inverse" in H2) > > ** > Any personal or sensitive information contained in > this email and > attachments must be handled in accordance with the > Victorian Information > Privacy Act 2000, the Health Records Act 2001 or the > Privacy Act 1988 > (Commonwealth), as applicable. > > This email, including all attachments, is > confidential. If you are not the > intended recipient, you must not disclose, > distribute, copy or use the > information contained in this email or attachments. > Any confidentiality or > privilege is not waived or lost because this email > has been sent to you in > error. If you have received it in error, please let > us know by reply > email, delete it from your system and destroy any > copies. > ** > > > > > > --- > This SF.NET email is sponsored by: > SourceForge Enterprise Edition + IBM + LinuxWorld = > Something 2 See! > http://www.vasoftware.com > ___ > hibernate-devel mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/hibernate-devel __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com --- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com ___ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
[Hibernate] what does "readonly=true" mean in a bidirectional association?
Use the example from hibernate-reference manual: Here the children set in the Parent object is readonly. Does it mean any modification to any "Child element" in the Children set will not be persisted to database( an violation of usual persistence by reachability)? In this sense, the "readonly" applies to the set element. Or Does it mean any addition and removal from the Children set will not be persisted to the database? In this sense, the "readonly" applies to the set itself. If we have a bidirectinoal association, but I do not specify the readonly for one end of the association. What can be resulted from it? Also why can the "readonly" attribute not be specified for element? Thanks Guys jason __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com --- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com ___ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
Re: [Hibernate] hib2 - parent in composite-element
I use the Java code instead of Hibernate to keep the parent-child relationship. For example suppose I have such a relationship Parent-->Level1-->Level2 The class implementation could be like this public class parent { public void setChild(Level1 child){ if (child.getParent()==null) child.setParent(this); ... } } //this class is a component right now. public class Level1 { public void setChild(Level2 child){ if (child.parent()==null) child.setParent(this); ... } } This implementation has two advantages: 1) you does not rely the tag for parent-child relationship mapping. 2) notice the following function call. Parent p=new Parent(); Level1 c=new Level1(); p.setChild(c); //the following call is not necessary with the above implementation. //c.setParent(p) Session.save(p); Of course, this is a workaround. jason. --- Viktor Szathmary <[EMAIL PROTECTED]> wrote: > hi, > > On Fri, 31 Jan 2003 16:02:49 +1100, > [EMAIL PROTECTED] said: > > > > private void setTopParent(TopLevelParent > topParent) { > >this.parent = topParent.getComponent(); > > } > > > > > > should do what you need ;) > > ok, it does not :) unfortunately the call sequence > is: > > - nestedChild.setParent( toplevel ) > - nested.setParent( toplevel ) > - toplevel.setChild( nested ) > > so, at the point when the nestedChild's parent > relationship is > estabilished, the toplevel object's downward > relationships are not > established yet. > > furthermore this whole thing makes things uglier, > since as far the object > model is concerned, a child now needs to have > dependencies on it's > toplevel parent (but this relationship might not > even be fixed). also, > due the the quirk i described above, the nested > child would need to keep > a reference to the toplevel object, so it can do > late binding... > > alltogether, i think the more useful behavior for > composite-element > parents' would be setting the immediate parent. > perhaps make it an > option... or pick based on the class specified, eg. > class="foo.bar.Baz"/>. > > best regards, > viktor > > -- > http://fastmail.fm - Does exactly what it says on > the tin > > > --- > This SF.NET email is sponsored by: > SourceForge Enterprise Edition + IBM + LinuxWorld = > Something 2 See! > http://www.vasoftware.com > ___ > hibernate-devel mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/hibernate-devel __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com --- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com ___ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
[Hibernate] set, bag and list
I have a collection of thing. I do not care whether there is duplication or not. I can use Set to prohibit duplication. I can also use list and bag. If I use Set rather than list/bag, I think the performance is not so good as it is for list/bag, since set has to limit duplication. I noticed that tag is required for list. But if I used linked list, I do not care about index. Can I omit the tag? Therefore I think bag is a good choice for my implementation: no index tag requirement and no performance penalty from set. However where the bag is declared? I looked through java.util.*. I did not find it. Thanks jason __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com --- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com ___ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
[Hibernate] hibernate set foreign key to null before issue deletion?
suppose I have two table create table A ( id integer primary key ); create table B ( id integer primary key, idA integer not null, constraint FK_B_TO_A foreign key (idA) references A (id) on delete cascade ); Here suppose A to B is a one-to-many association and I did not ask the hibernate to do the cascade in the mapping file since I do it in the database by specifying "on delete cascade"; I think it will be effecient to let the database to do the cascading deletion. (Am I right here?). If I call Session.delete(A), the Session will issue these two queries: 1. update B set idA = null where idA =? 2. delete from A where id = ? Apparently hibernate wants to dissociate B from A before it issues the deletion. How can I turn this off? Or any alternative solution? I am trying to convince my CTO to use hibernate in a project. However I promise a demo to him sometime today. Any help is really appreciated. jason __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com --- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com ___ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
Re: [Hibernate] should be added to ...?
--- [EMAIL PROTECTED] wrote: > > U. > > > You should use or > > makes no sense at all. I INDEED need a under ! My Top-level (not nested) table has a key column and element column (integer). However the element column is a foreign key (many-to-one) to another table (B in the example below). E.g: BAG TABLE TABLE B key integer id name . 11 1 "name1" 12 2 "name2" 13 3 "name3" 23 22 Here I wants the bag element(Java object) is type of B, not just the integer. Following current DTD, I have to encapsulate the which has a single under the . The question is why I can not use directly under ? "On a second thought / should be allowed anywhere / is allowed. For /, One columnis used to produce an instance of primitive type. For/ one column (and another table) is used to produce a user-defined type." Is this statement is correct? This is a abstract example. My previous example(below) is a concrete example I encoutered in my application. Thanks jason > > > > > > jiesheng zhang > > > <[EMAIL PROTECTED]> >To: [EMAIL PROTECTED] > > Sent by: >cc: > > > [EMAIL PROTECTED] Subject: > [Hibernate] should be added to > ...? > eforge.net > > > > > > > > > 03/02/03 06:11 PM > > > > > > > > > > > > > I have one usage scenario as below: > > The classes could be like this. > public class Person { >... >List Addresses; //A list of Address > objects. > } > public class Address { >... >List types; //A list of AddressType > object > } > public class AddressType { >long typenum; >String typename; > } > > > The database schema could be like this. > creat table addressType ( >typenum varchar(20) primary key, >typename varchar(40) not null >); > /* > * Table models a collection of address type. > */ > create table addressTypes ( >collectionID integer, >type integer, >constraint FK_ADDRESSTYPE_TO_STRING > foreign key > (type) references addresstype (typenum) >); > create sequence seq_ats; > create table person ( >id integer primary key, >... >); > create table address ( >personid integer not null, >... >types integer, /* The type references the > collectionID in the AddressTypes above */ > >constraint FK_ADDRESS_TO_PERSON foreign > key > (companyid) references person (id) >); > > > The mapping file is like this > > > > >seq_ats > > > >class="AddressType"/> > > > > > > > >... > > > > > > > > ... > > > > >... > > role="addressTypes"/> > > > > > > Thanks > > jason > > > __ > Do you Yahoo!? > Yahoo! Mail Plus - Powerful. Affordable. Sign up > now. > http://mailplus.yahoo.com > > > --- > This SF.N
[Hibernate] any successful story with hibernate?
Hi, guys I am currently designing a Java project. I'd like to use a Object relational mapping tool to manage the persistnece layer. My friend suggests hibernate for me. Other people also warns me about the capability of Object relation mapping solution. This makes me worry about the hibernate capability. I have two questions? First is there a real example commercial application which used hibernate? What is the difference between object bridge hosted by Apache and hibernate? Thanks jason __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com --- This SF.net email is sponsored by: Scholarships for Techies! Can't afford IT training? All 2003 ictp students receive scholarships. Get hands-on training in Microsoft, Cisco, Sun, Linux/UNIX, and more. www.ictp.com/training/sourceforge.asp ___ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
Re: [Hibernate] hibernate set foreign key to null before issue deletion?
Clarify my question here: suppose I have two table create table A ( id integer primary key ); create table B ( id integer primary key, idA integer not null, constraint FK_B_TO_A foreign key (idA) references A (id) on delete cascade ); Here suppose A to B is a one-to-many association and I did not ask the hibernate to do the cascade in the mapping file since I will do it in database by specifying "on delete cascade"; I think it will be effecient to let the database to do the cascading deletion. (Am I right here?). If I call Session.delete(A), the Session will issue these two queries: 1. update B set idA = null where idA =? 2. delete from A where id = ? This causes some problem. 1. I specify the foreign key idA is not null. So the first query will always fail. 2. Suppose I remove "not null" constraint on the foreign key idA and ask the database to do the cascading deletion. If hibernate sets the foreign key to null, database will not be able to do the cascading deletion since the key is NULL right now (not idA any more). It seems the only workable solution is: remove all not null constraint on the foreign key and let hibernate to manage the cascade deletion. Is there any way I can turn off the "set null " update before deletion metioned above? Thanks jason. __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com --- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com ___ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
[Hibernate] interface and implemenation mapping
Suppose we have a interface A, and an implemenation class A_Impl. In this case, there is no discriminator column and discrimator value. Can I use ... to map this? Or I have to use http://mailplus.yahoo.com --- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com ___ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
Re: [Hibernate] How to do this (assiciation)?
Can I implement this as this? Leave Address as a interface. Class ToAddress--- mapped to address with type='t' class CCAddress---mapped to Address with type='c' Then in Class has two sets toaddr mapped to a list of ToAddress ccaddrmapped to a list of CCAddress Althought I did not try, but it should work. jason --- [EMAIL PROTECTED] wrote: > > Nup, it's not allowed currently. It would probably > be pretty trivial to > support in the same way we support the order-by > attribute ... simply have a > where attribute of a collection mapping. If you want > to try implementing > that, please feel welcome since many people have > asked for this. Currently > each collection requires its own foreign key column. > > I am not so keen on this kind of model, actually. > > > > > > > "Aapo Laakkonen" > > > <[EMAIL PROTECTED]> >To: > <[EMAIL PROTECTED]> > > Sent by: >cc: > > > [EMAIL PROTECTED] Subject: > [Hibernate] How to do this (assiciation)? > > eforge.net > > > > > > > > > 13/02/03 02:16 AM > > > Please respond to aapo.laakkonen > > > > > > > > > > > > > Let's say I have a Message table: > message (id, subject, content, toaddr, ccaddr) > > - id = long identifier > - subject = text string > - content = text string > - toaddr = mapping to a address table with > address.type='t'. > - ccaddr = mapping to a address table with > address.type='c'. > > Or it can be an integer or anything else... maybe an > enumeration. > > And I have a table Address: > address (id, message_id, email, type) > > - id = long identifier > - message_id = long foreign key relation to message > table > - email = text string > - type = type that identifies the type of this > address field (to-address > or cc-address). > > I'd like to to mapping so that my Message class > looks something like > this: > > public class AddressBean implements Serializable { >private long id; >private String subject; >private String Content; >private Set toaddr; >private Set ccaddr; > } > > - Each message has zero to many to-addresses. > - Each message has zero to many cc-addresses. > - Each address belongs to exactly one message. > > How do I write a mapping for that? Hibernate needs > to somehow know that > we are mapping toaddr set to address table that has > a particular > address.message_id and address.type. > > > Kind Regards > Aapo Laakkonen > > > > --- > This SF.NET email is sponsored by: > SourceForge Enterprise Edition + IBM + LinuxWorld = > Something 2 See! > http://www.vasoftware.com > ___ > hibernate-devel mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/hibernate-devel > > > > > ** > Any personal or sensitive information contained in > this email and > attachments must be handled in accordance with the > Victorian Information > Privacy Act 2000, the Health Records Act 2001 or the > Privacy Act 1988 > (Commonwealth), as applicable. > > This email, including all attachments, is > confidential. If you are not the > intended recipient, you must not disclose, > distribute, copy or use the > information contained in this email or attachments. > Any confidentiality or > privilege is not waived or lost because this email > has been sent to you in > error. If you have received it in error, please let > us know by reply > email, delete it from your system and destroy any > copies. > **
[Hibernate] should be added to ...?
I have one usage scenario as below: The classes could be like this. public class Person { ... List Addresses; //A list of Address objects. } public class Address { ... List types; //A list of AddressType object } public class AddressType { long typenum; String typename; } The database schema could be like this. creat table addressType ( typenum varchar(20) primary key, typename varchar(40) not null ); /* * Table models a collection of address type. */ create table addressTypes ( collectionID integer, type integer, constraint FK_ADDRESSTYPE_TO_STRING foreign key (type) references addresstype (typenum) ); create sequence seq_ats; create table person ( id integer primary key, ... ); create table address ( personid integer not null, ... types integer, /* The type references the collectionID in the AddressTypes above */ constraint FK_ADDRESS_TO_PERSON foreign key (companyid) references person (id) ); The mapping file is like this seq_ats ... ... ... Thanks jason __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com --- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com ___ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
Re: [Hibernate] Parent / Child Mapping with composite-id
> > table="child"> > class="org.appfuse.persistence.ChildId" > unsaved-value="none"> > length="22" name="parentId" > type="long"/> Try this: and remove the the below. > length="22" name="recordNum" > type="long"/> > > name="name" type="string"/> > name="description" > type="string"/> > column="parent_id" not-null="true"/> > > > > I get: > > [junit] java.sql.BatchUpdateException: General > error: Column 'parent_id' > specified twice > > > To make it work, I've specified readonly="true" on > the parent's mapping, and > explicity saved the child objects. This seems to be > the desired path for > using Hibernate? Am I correct? > > Parent's mapping: > > readonly="true" cascade="all"> > > class="org.appfuse.persistence.Child"/> > > > In order to update properly: > > Iterator it = > p.getChildren().iterator(); > > while (it.hasNext()) { > Child c = (Child) it.next(); > ses.update(c); > } > > ses.update(p); > ses.flush(); > > Thanks, > > Matt > > > > --- > This SF.NET email is sponsored by: > SourceForge Enterprise Edition + IBM + LinuxWorld = > Something 2 See! > http://www.vasoftware.com > ___ > hibernate-devel mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/hibernate-devel __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com --- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com ___ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
Re: [Hibernate] hib2 - parent in composite-element
--- Viktor Szathmary <[EMAIL PROTECTED]> wrote: > hi, > > On Mon, 3 Feb 2003 09:32:39 +1100, > [EMAIL PROTECTED] said: > > > > Are there proxies involved? > > > > hopefully not :) it seems that there's actually two > calls to > nestedChild.setParent() on the same nestedChild > instance - the second one > occurs during deepCopy, and blows away the value > that was set first... If you do not use tag, setOrigin() will not be called by hibernate. How come the deepcopy( part of hibernate, isn't it) calls the setOrigin()? Do you mix the setOrigin() from hibernate and java implementation? jason. > here are the stacktraces (the assertion in the > testcase expected the > parent to be [EMAIL PROTECTED]): > > [EMAIL PROTECTED]( > [EMAIL PROTECTED] ): > > at > net.sf.flock.hibernate.Item.setOrigin(Item.java:28) > at > net.sf.flock.hibernate.Feed.setItems(Feed.java:31) > at > sun.reflect.NativeMethodAccessorImpl.invoke0(Native > Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:324) > at > net.sf.hibernate.util.ReflectHelper$Setter.set(ReflectHelper.java:39) > at > net.sf.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:132) > at > net.sf.hibernate.type.AbstractType.hydrate(AbstractType.java:64) > at > net.sf.hibernate.loader.Loader.hydrate(Loader.java:348) > at > net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:298) > at > net.sf.hibernate.loader.Loader.doFind(Loader.java:142) > at > net.sf.hibernate.loader.Loader.find(Loader.java:487) > at > net.sf.hibernate.hql.QueryTranslator.find(QueryTranslator.java:951) > at > net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1186) > at > net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1165) > at > net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1161) > at > net.sf.flock.hibernate.HibernateSubscriptionManager.loadSubscription(HibernateSubscriptionManager.java:72) > at > net.sf.flock.hibernate.HibernateSubscriptionManagerTest.testPersistence(HibernateSubscriptionManagerTest.java:50) > > ... and then... > [EMAIL PROTECTED]( > [EMAIL PROTECTED] ): > > at > net.sf.flock.hibernate.Item.setOrigin(Item.java:28) > at > net.sf.flock.hibernate.Feed.setItems(Feed.java:31) > at > sun.reflect.NativeMethodAccessorImpl.invoke0(Native > Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:324) > at > net.sf.hibernate.util.ReflectHelper$Setter.set(ReflectHelper.java:39) > at > net.sf.hibernate.type.ComponentType.setPropertyValues(ComponentType.java:181) > at > net.sf.hibernate.type.ComponentType.deepCopy(ComponentType.java:204) > at > net.sf.hibernate.type.TypeFactory.deepCopy(TypeFactory.java:188) > at > net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1743) > at > net.sf.hibernate.loader.Loader.doFind(Loader.java:180) > at > net.sf.hibernate.loader.Loader.find(Loader.java:487) > at > net.sf.hibernate.hql.QueryTranslator.find(QueryTranslator.java:951) > at > net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1186) > at > net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1165) > at > net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1161) > at > net.sf.flock.hibernate.HibernateSubscriptionManager.loadSubscription(HibernateSubscriptionManager.java:72) > at > net.sf.flock.hibernate.HibernateSubscriptionManagerTest.testPersistence(HibernateSubscriptionManagerTest.java:50) > > -- > http://fastmail.fm - And now for something > completely different... > > > --- > This SF.NET email is sponsored by: > SourceForge Enterprise Edition + IBM + LinuxWorld = > Something 2 See! > http://www.vasoftware.com > ___ > hibernate-devel mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/hibernate-devel __ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com --- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com ___ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
[Hibernate] experince in equals() and hashCode()
import java.util.Random; public class A { // the object id, unsaved=0; private long id=0; private String value; public boolean equals(Object obj) { if (obj==this) { /* * This actually does not wotk simetime. * In some case I know two objects refer the same instance, * however the control flow does not return from here. * * I do not know why, may be caused by the proxy implementation. */ return true; } if (obj instanceof A) { A a=(A)obj; // judge the equality of persistence objects based on id /* * Use getId() here. Do not use the id member variable directly. * The getId() sometime returns a value different from that of id member variable. * * Is this because that the Proxy implementation * intercept the getId() call? * */ // at least one instance is a persistent instance. if ((getId()+a.getId())!=0) { // if the id is equals, they are equal. if (getId()==a.getId()) return true; else return false; } else { // judge the equality base on field semantic. if (value.equals(a.getValue())) return true; return false; } } else return false; } /** * Id is a very good candidate for hashCode. * It guaranttes that the id is different for every instance for the same type of object. * * The rule is that the hashCode() can not change in one Hibernate * session even the information(value member variable here) * used in equals() comparison changes. Why? This is a consideration for the java.util.HashSet * implementation. Suppose you have an object in java.util.Hashset, you modify the object value * and the HashCode() right now returns a value different from that before the object is inserted * into the HashSet. Right now, you have no way to remove the object from the HashSet. * The Hashset assumes that the hashCode() returns an invariable value. * * For this reason, if the transient object (id is 0) is changed to persistent object, its hashCode() * can not be changed according to the id value. Therefore we cache the hashCode() here. Once the hashCode() * is called by the JVM, it is invariable. * * * However this implementation violate the hashCode() contract in some case. * For example, suppose that an transient object is persisted with a id(500) (hashCode is randomly generated). * From other source(session), we get another object with a id (500) (hashCode is 500). * These two objects are equal, but the hashCode() is different. * * This kind of situation is ignored here. Application developer should understand the impact of * the hashCode() implementation and take action to avoid such case. */ private int hashcode=-1; public int hashCode() { if (hashcode==-1) if (id==0) hashcode=(new Random()).nextInt(); else hashcode=(int)id; return hashcode; } public long getId() { return id; } public void setId(long l) { id= l; } public String getValue() { return value; } public void setValue(String string) { value= string; } } hope my experience is helpful. __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com --- This sf.net email is sponsored by:ThinkGeek Welcome to
[Hibernate] proxy, abstract class, ClassCastException.
My problem is that I know one object is type A, but when I try to cast to A, I got a ClassCastException. I have four classes in my cases: ContentDB, ServerFileSysNode, InnerNode, and SharedFileSysNode. ServerFileSysNode(abstract) InnerNode (concrete subclass of ServerFileSysNode, may have an asscoaited SharedFileSysNode). ...(other subclass of ServerFileSysNode is omitted here ). ShareFileSysNode always associated with a ServerFileSysNode ContentDB( a list of ServerFileSysNode, a list of SharedFileSysNode). Their mapping are shown at the bottom. In my application initialization, I loaded all the ServerFileSysNode and ShareFileSysNode in the ContentDB. However I found that if an InnerNode does not have an associated SharedFileSysNode, the InnerNode will have a type of "InnerNode", that is correct. Otherwise, it will have a type of "ServerFileSysNode$$EnhancedByCGLIB$$00", and the "ServerFileSysNode$$EnhancedByCGLIB$$00" can not cast back to "InnerNode". I just wonder how the hibernate decides that the object should be "ServerFileSysNode$$EnhancedByCGLIB$$00". Since ServerFileSysNode is an abstract clas. In my database, there is no instance which is object of "ServerFileSysNode" Also I did not use the Session.load(Class, id) method to load the object explicitly. All the objects are loaded by association with the ContentDB. Help is appreciated. seq_resourceID seq_resourceID hardNode __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com --- 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] self-referential table
It definitely works. I have many such methods like what you mentioned. Post your method implementation and exception here. Let me have a look. jason --- Warner Onstine <[EMAIL PROTECTED]> wrote: > Got this working! > > Now I have another question with regards to > collections in general. > > I tried to do this: > Set subCategories; > > public void setSubCategories() > public Set getSubCategories() > public void addSubCategory() > public void removeSubCategory() > > in add and remove I refer to the collection > subCategories.add(subCat) > and inversely for remove. When I put this through my > test class it spit > up a nasty reflection error so I went back to using > the > setSubCategories() instead and everything worked > alright. > > It would be nice to have a helper method like this > defined in my class, > is it possible with Hibernate though? > > Thanks, > Warner > __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com --- 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
[Hibernate] bad performance during flush and help is needed.
My system is a prototype system. There is only one test user at any time. For this user, there is about 500-600 objects loaded in the Hibernate session at maximal. Very often, my application needs to change only one field in one object and commit the transaction. My code is like this Tranaction tx=sessiob.beginTransaction(); foo.setField(newValue); tx.commit(); However the modification and commit logic need to repeat about 500 times before the control is returned to user. I found the performance is really bad. One transaction take about one second. It takes about 10 minutes to finish the whole modification logic. This performance is intolerable. 1. When the commit() is called, will the hibernate loop through every object in the session and check for modification? 2. If it does, is it an expensive operation? Any suggestion to solve the performance bottleneck in my situation is really appreacited. Should I use SQL directly instead of Hibernate to do the commit for this case? jason __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com --- 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] bad performance during flush and help is needed.
--- Gavin King <[EMAIL PROTECTED]> wrote: > So, let me get this straight: > > you, *500 times* > > (a) obtain a new JDBC connection > (b) start a transaction > (c) do some work > (d) commit the transaction and close the JDBC > connection Not quite that. I, *500 times* (a') using the same connection. (b) start a transaction. (c) only persist a transient object. (d) commit the transaction, but do not close the JDBC. > > and you are surprised that this is slow?? > > Why would you not do it all in one transaction? > Starting and stopping > transactions is one of _the_ most expensive > operations you can do with a > database. The request is from client-side (an embedded client in consumer device). The client explicitly specifies the transaction boudary in its message. Forget about the 500 transactions. The problem is this: with 300-500 objects in the session cache, a single transaction( with an single object inserted) takes about one second. I am thinking of this idea: Using a session to load object only(read-only session). Use a new session for every transaction just make sure that there is no object is cached in the session. Obtaining database connection should not be a problem since the database connection is pooled at Tomcat layer. How do you think of this idea? Thanks jason > jiesheng zhang wrote: > > >First I have a source class like this. > >public class Source > >{ > > Transaction tx; > > > > List pendingRemovedItems; > > public void beginTransaction() > > { > > // here I use ThreadLocal pattern. > > tx= ThreadState.getSession().beginTransaction(); > > } > > > > public void commit() > > { > > try > > { > > // I need to explicitly delete all items that > need > >deletion. > > for (Iterator iter= > pendingRemovedItems.iterator(); > > iter.hasNext(); > > ) > > { > > ThreadState.getSession().delete(iter.next()); > > } > > > > tx.commit(); > > logger.info(" db source is commited"); > > pendingRemovedItems.clear(); > > } finally > > { > > tx= null; > > } > > } > > > > // other variables and methods in source. > >} > > > > > >My application code is like this > >Source src=...; > >// when control comes here, there are about 500 > >persistence objects in session. > >1. src.beginTransaction(); > >2. // here an new transient object is persisted. > >3. src.commit(); > > > >The code fragment 1, 2, and 3 will be run 300 to > 500 > >times. > > > > > >The following is sql code dumped from hibernate. > That > >is exactly what I expected. I only show 2 of them. > The > >timestamp indicated that each insertion was about > one > >second. > > > >I am happy to provide any extra information. > > > > > >2003-9-12 12:31:02 > >Info: found cached source > >Hibernate: select seq_resourceID.nextval from dual > >Hibernate: insert into contact (luid, dbId, guid, > >namefirst, namelast, nameother, nameprefix, > >namesuffix, title, role, orgname, orgunit, > birthday, > >url, nickname, timezone, note, binary, categories, > >class, contactID) values (?, ?, ?, ?, ?, ?, ?, ?, > ?, > >?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'd', ?) > >Hibernate: insert into phonenumber (contactID, num, > >type) values (?, ?, ?) > >Hibernate: insert into email (contactID, email, > type) > >values (?, ?, ?) > >2003-9-12 12:31:03 ... > >Info: db source is commited > >2003-9-12 12:31:03 > > > >2003-9-12 12:31:03 ... > >Info: found cached source > >Hibernate: select seq_resourceID.nextval from dual > >Hibernate: insert into contact (luid, dbId, guid, > >namefirst, namelast, nameother, nameprefix, > >namesuffix, title, role, orgname, orgunit, > birthday, > >url, nickname, timezone, note, binary, categories, > >class, contactID) values (?, ?, ?, ?, ?, ?, ?, ?, > ?, > >?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'd', ?) > >Hibernate: insert into email (contactID, email, > type) > >values (?, ?, ?) > >Hibernate: insert into phonenumber (contactID, num, > >type) values (?, ?, ?) > >2003-9-12 12:31:04 ... > >Info: db source is commi
Re: [Hibernate] bad performance during flush and help is needed.
First I have a source class like this. public class Source { Transaction tx; List pendingRemovedItems; public void beginTransaction() { // here I use ThreadLocal pattern. tx= ThreadState.getSession().beginTransaction(); } public void commit() { try { // I need to explicitly delete all items that need deletion. for (Iterator iter= pendingRemovedItems.iterator(); iter.hasNext(); ) { ThreadState.getSession().delete(iter.next()); } tx.commit(); logger.info(" db source is commited"); pendingRemovedItems.clear(); } finally { tx= null; } } // other variables and methods in source. } My application code is like this Source src=...; // when control comes here, there are about 500 persistence objects in session. 1. src.beginTransaction(); 2. // here an new transient object is persisted. 3. src.commit(); The code fragment 1, 2, and 3 will be run 300 to 500 times. The following is sql code dumped from hibernate. That is exactly what I expected. I only show 2 of them. The timestamp indicated that each insertion was about one second. I am happy to provide any extra information. 2003-9-12 12:31:02 Info: found cached source Hibernate: select seq_resourceID.nextval from dual Hibernate: insert into contact (luid, dbId, guid, namefirst, namelast, nameother, nameprefix, namesuffix, title, role, orgname, orgunit, birthday, url, nickname, timezone, note, binary, categories, class, contactID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'd', ?) Hibernate: insert into phonenumber (contactID, num, type) values (?, ?, ?) Hibernate: insert into email (contactID, email, type) values (?, ?, ?) 2003-9-12 12:31:03 ... Info: db source is commited 2003-9-12 12:31:03 2003-9-12 12:31:03 ... Info: found cached source Hibernate: select seq_resourceID.nextval from dual Hibernate: insert into contact (luid, dbId, guid, namefirst, namelast, nameother, nameprefix, namesuffix, title, role, orgname, orgunit, birthday, url, nickname, timezone, note, binary, categories, class, contactID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'd', ?) Hibernate: insert into email (contactID, email, type) values (?, ?, ?) Hibernate: insert into phonenumber (contactID, num, type) values (?, ?, ?) 2003-9-12 12:31:04 ... Info: db source is commited --- Gavin King <[EMAIL PROTECTED]> wrote: > > >the transaction. My code is like this > > > >Tranaction tx=sessiob.beginTransaction(); > >foo.setField(newValue); > >tx.commit(); > > > > Well, obviously it is not like that, since that code > does not > load any objects into the session. > > >1. When the commit() is called, will the hibernate > >loop through every object in the session > >and check for modification? > > > Yes. > > >2. If it does, is it an expensive operation? > > > > No, not at all. > > >Any suggestion to solve the performance bottleneck > in > >my situation is really appreacited. > > > > Exactly what does your code *really* look like? > > __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com --- 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
[Hibernate] some performnace metric for the dirty check during hibernate flush.
Hi, I once suspect that hibernate take too much time in doing dirty check during session flush. However Gavin king and other hibernate-user disagreed with me. I did a simple performance testing to verify the dirty check performance. My conslusion is that the performance is not so good if there are many objects in session. If a session has around 1000 objects in memory, only will the dirty check take about 200 million second. For detailed performance metrics, see the table below. The structure of my testing object is very simple. One thing I am not sure is whether the dirty checking algorithm is related to object structure or not. If it is, the dirty check in reality will take more time. My testing case is attached. ---test logic 1. load some (n) number of objects in memory. 2. begin tranaction. 3. // do not do anything here. 4. commit. Then calculate the time consumed from step 2 and 4. test code - List ps=new ArrayList(10010); for (int i=1000; i<2100; i++) { Parent p1=(Parent)session.load(Parent.class, new Long(i)); p1.getValues().size(); } long startTime=System.currentTimeMillis(); Transaction tx=session.beginTransaction(); tx.commit(); long endTime=System.currentTimeMillis(); System.out.println("total time(in ms):"+(endTime-startTime)); -The performance metics- objects in memory time (in ms) for dirty check (3 experiments) 1 741, 751,821 2000200, 230, 230 1000201, 191, 190, 100 30, 30, 30 1 10, 10, 10 jason __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com src.zip Description: src.zip