From: <leg...@at...> - 2003-09-25 16:58:55
|
The following issue has been updated: Updater: Brian Bonner (mailto:bri...@pa...) Date: Thu, 25 Sep 2003 11:58 AM Comment: Doh! I didn't see that I could attach a file when I was creating the report. Sorry about that. Changes: Attachment changed to failing.jar --------------------------------------------------------------------- For a full history of the issue, see: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-362&page=history --------------------------------------------------------------------- View the issue: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-362 Here is an overview of the issue: --------------------------------------------------------------------- Key: HB-362 Summary: Save with native ID on DB2 fails with duplicate row exception if data inserted behind hibernate Type: Bug Status: Unassigned Priority: Critical Project: Hibernate2 Versions: 2.0.3 Assignee: Reporter: Brian Bonner Created: Thu, 25 Sep 2003 11:53 AM Updated: Thu, 25 Sep 2003 11:58 AM Environment: Win 2K SP4, JDK 1.4.2, Hibernate 2.0.3, DB2 7.2 UDB Description: If we restart the database manager (clean state), then execute the DDL generated by hibernate, and run the test case: TestHibernate records are inserted without problem. We can rerun the test case numerous times. If we restart the database manager, then insert data from a command line (behind hibernate): insert into parents values(1,'test','test','test','test',current timestamp); insert into children values (1,'bb','1); insert into children values (2,'cc','1); and run the test case, it fails. hibernate.properties, Mapping, generated DDL, Domain Source, Test Source follows. hibernate.connection.driver_class = COM.ibm.db2.jdbc.app.DB2Driver hibernate.dialect = net.sf.hibernate.dialect.DB2Dialect hibernate.connection.url = jdbc:db2:sample hibernate.connection.username = xyz hibernate.connection.password = pdq <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="com.paraware.domain.Parent" table="parents"> <id name="keyId" type="int" unsaved-value="0"> <column name="key_id" not-null="true"/> <generator class="native"/> </id> <property name="userID" column="LogonID" type="string"/> <property name="userName" column="Name" type="string"/> <property name="password" type="string"/> <property name="emailAddress" type="string"/> <property name="lastLogon" type="timestamp"/> <set name="children" table="children" cascade="all" lazy="true" inverse="true"> <key column="key_id"/> <one-to-many class="com.paraware.domain.Child"/> </set> </class> </hibernate-mapping> <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="com.paraware.domain.Child" table="children"> <id name="mouseId" type="int" unsaved-value="0"> <column name="mouse_id" not-null="true"/> <generator class="native"/> </id> <property name="name" column="name" type="string"/> <many-to-one name="parent" class="com.paraware.domain.Parent" column="key_id" /> </class> </hibernate-mapping> drop table parents; drop table children; create table parents ( key_id INTEGER not null generated by default as identity, LogonID VARCHAR(255), Name VARCHAR(255), password VARCHAR(255), emailAddress VARCHAR(255), lastLogon TIMESTAMP, primary key (key_id) ); create table children ( mouse_id INTEGER not null generated by default as identity, name VARCHAR(255), key_id INTEGER, primary key (mouse_id) ); alter table children add constraint FK62EA5DFFBC5E42FB foreign key (key_id) references parents; package com.paraware.domain; import java.util.Date; import java.util.Set; // ... public class Parent { private int keyId; private String userID; private String userName; private String password; private String emailAddress; private Date lastLogon; private Set children; public int getKeyId() { return keyId; } public void setKeyId(int keyId) { this.keyId = keyId; } public String getUserID() { return userID; } public void setUserID(String newUserID) { userID = newUserID; } public String getUserName() { return userName; } public void setUserName(String newUserName) { userName = newUserName; } public String getPassword() { return password; } public void setPassword(String newPassword) { password = newPassword; } public String getEmailAddress() { return emailAddress; } public void setEmailAddress(String newEmailAddress) { emailAddress = newEmailAddress; } public Date getLastLogon() { return lastLogon; } public void setLastLogon(Date newLastLogon) { lastLogon = newLastLogon; } public Set getChildren() { return children; } public void setChildren(Set mouses) { this.children = mouses; } /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object obj) { if (this == obj) return true; if ((obj == null) || (obj.getClass() != this.getClass())) return false; // Must be the Parent Parent other = (Parent) obj; return userID == other.userID || userID != null && userID.equals(other.userID) && userName == other.userName || userName != null && userName.equals(other.userName); } /* (non-Javadoc) * @see java.lang.Object#hashCode() */ public int hashCode() { int result = 17; result = userID == null ? result : 37 * result + userID.hashCode(); result = userName == null ? result : 37 * result + userName.hashCode(); return result; } } package com.paraware.domain; public class Child { private int mouseId; private String name; private Parent parent; public int getMouseId() { return mouseId; } public void setMouseId(int id) { this.mouseId = id; } public String getName() { return name; } public void setName(String newName) { name = newName; } public Parent getParent() { return parent; } public void setParent(Parent newUser) { parent = newUser; } /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object obj) { if (this == obj) return true; if ((obj == null) || (obj.getClass() != this.getClass())) return false; // Must be the Child Child other = (Child) obj; return name == other.name || name != null && name.equals(other.name); } /* (non-Javadoc) * @see java.lang.Object#hashCode() */ public int hashCode() { int result = 17; result = name == null ? result : 37 * result + name.hashCode(); return result; } } package com.paraware; import java.sql.SQLException; import java.util.Date; import java.util.HashSet; import java.util.Set; import net.sf.hibernate.HibernateException; import net.sf.hibernate.Session; import net.sf.hibernate.SessionFactory; import net.sf.hibernate.Transaction; import net.sf.hibernate.cfg.Configuration; import com.paraware.domain.Child; import com.paraware.domain.Parent; public class TestHibernate { public static void main(String args[]) throws HibernateException, SQLException { SessionFactory sessionFactory; Transaction transaction; Configuration cfg = new Configuration(); cfg.addClass(Parent.class); cfg.addClass(Child.class); sessionFactory = cfg.buildSessionFactory(); Session session = sessionFactory.openSession(); transaction = session.beginTransaction(); Parent newUser = new Parent(); newUser.setUserID("bnnn"); newUser.setUserName("Vivi"); newUser.setPassword("abcff"); newUser.setEmailAddress("vi...@co..."); newUser.setLastLogon(new Date()); session.save(newUser); Child ms1 = new Child(); ms1.setName("Mickey"); Child ms2 = new Child(); ms2.setName("Mouse"); Set mouseSet = new HashSet(); mouseSet.add(ms1); mouseSet.add(ms2); //set up association newUser.setChildren(mouseSet); //save foreign keys ms1.setParent(newUser); ms2.setParent(newUser); transaction.commit(); // close our session and release resources session.flush(); session.close(); } } --------------------------------------------------------------------- JIRA INFORMATION: This message is automatically generated by JIRA. If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira |
From: <leg...@at...> - 2003-09-25 17:21:55
|
The following issue has been updated: Updater: Brian Bonner (mailto:bri...@pa...) Date: Thu, 25 Sep 2003 12:21 PM Comment: I tried to run this with 2.1b3 and received similar errors. Changes: Attachment changed to hibernate.2.1b3.log --------------------------------------------------------------------- For a full history of the issue, see: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-362&page=history --------------------------------------------------------------------- View the issue: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-362 Here is an overview of the issue: --------------------------------------------------------------------- Key: HB-362 Summary: Save with native ID on DB2 fails with duplicate row exception if data inserted behind hibernate Type: Bug Status: Unassigned Priority: Critical Project: Hibernate2 Versions: 2.0.3 Assignee: Reporter: Brian Bonner Created: Thu, 25 Sep 2003 11:53 AM Updated: Thu, 25 Sep 2003 12:21 PM Environment: Win 2K SP4, JDK 1.4.2, Hibernate 2.0.3, DB2 7.2 UDB Description: If we restart the database manager (clean state), then execute the DDL generated by hibernate, and run the test case: TestHibernate records are inserted without problem. We can rerun the test case numerous times. If we restart the database manager, then insert data from a command line (behind hibernate): insert into parents values(1,'test','test','test','test',current timestamp); insert into children values (1,'bb','1); insert into children values (2,'cc','1); and run the test case, it fails. hibernate.properties, Mapping, generated DDL, Domain Source, Test Source follows. hibernate.connection.driver_class = COM.ibm.db2.jdbc.app.DB2Driver hibernate.dialect = net.sf.hibernate.dialect.DB2Dialect hibernate.connection.url = jdbc:db2:sample hibernate.connection.username = xyz hibernate.connection.password = pdq <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="com.paraware.domain.Parent" table="parents"> <id name="keyId" type="int" unsaved-value="0"> <column name="key_id" not-null="true"/> <generator class="native"/> </id> <property name="userID" column="LogonID" type="string"/> <property name="userName" column="Name" type="string"/> <property name="password" type="string"/> <property name="emailAddress" type="string"/> <property name="lastLogon" type="timestamp"/> <set name="children" table="children" cascade="all" lazy="true" inverse="true"> <key column="key_id"/> <one-to-many class="com.paraware.domain.Child"/> </set> </class> </hibernate-mapping> <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> <hibernate-mapping> <class name="com.paraware.domain.Child" table="children"> <id name="mouseId" type="int" unsaved-value="0"> <column name="mouse_id" not-null="true"/> <generator class="native"/> </id> <property name="name" column="name" type="string"/> <many-to-one name="parent" class="com.paraware.domain.Parent" column="key_id" /> </class> </hibernate-mapping> drop table parents; drop table children; create table parents ( key_id INTEGER not null generated by default as identity, LogonID VARCHAR(255), Name VARCHAR(255), password VARCHAR(255), emailAddress VARCHAR(255), lastLogon TIMESTAMP, primary key (key_id) ); create table children ( mouse_id INTEGER not null generated by default as identity, name VARCHAR(255), key_id INTEGER, primary key (mouse_id) ); alter table children add constraint FK62EA5DFFBC5E42FB foreign key (key_id) references parents; package com.paraware.domain; import java.util.Date; import java.util.Set; // ... public class Parent { private int keyId; private String userID; private String userName; private String password; private String emailAddress; private Date lastLogon; private Set children; public int getKeyId() { return keyId; } public void setKeyId(int keyId) { this.keyId = keyId; } public String getUserID() { return userID; } public void setUserID(String newUserID) { userID = newUserID; } public String getUserName() { return userName; } public void setUserName(String newUserName) { userName = newUserName; } public String getPassword() { return password; } public void setPassword(String newPassword) { password = newPassword; } public String getEmailAddress() { return emailAddress; } public void setEmailAddress(String newEmailAddress) { emailAddress = newEmailAddress; } public Date getLastLogon() { return lastLogon; } public void setLastLogon(Date newLastLogon) { lastLogon = newLastLogon; } public Set getChildren() { return children; } public void setChildren(Set mouses) { this.children = mouses; } /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object obj) { if (this == obj) return true; if ((obj == null) || (obj.getClass() != this.getClass())) return false; // Must be the Parent Parent other = (Parent) obj; return userID == other.userID || userID != null && userID.equals(other.userID) && userName == other.userName || userName != null && userName.equals(other.userName); } /* (non-Javadoc) * @see java.lang.Object#hashCode() */ public int hashCode() { int result = 17; result = userID == null ? result : 37 * result + userID.hashCode(); result = userName == null ? result : 37 * result + userName.hashCode(); return result; } } package com.paraware.domain; public class Child { private int mouseId; private String name; private Parent parent; public int getMouseId() { return mouseId; } public void setMouseId(int id) { this.mouseId = id; } public String getName() { return name; } public void setName(String newName) { name = newName; } public Parent getParent() { return parent; } public void setParent(Parent newUser) { parent = newUser; } /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object obj) { if (this == obj) return true; if ((obj == null) || (obj.getClass() != this.getClass())) return false; // Must be the Child Child other = (Child) obj; return name == other.name || name != null && name.equals(other.name); } /* (non-Javadoc) * @see java.lang.Object#hashCode() */ public int hashCode() { int result = 17; result = name == null ? result : 37 * result + name.hashCode(); return result; } } package com.paraware; import java.sql.SQLException; import java.util.Date; import java.util.HashSet; import java.util.Set; import net.sf.hibernate.HibernateException; import net.sf.hibernate.Session; import net.sf.hibernate.SessionFactory; import net.sf.hibernate.Transaction; import net.sf.hibernate.cfg.Configuration; import com.paraware.domain.Child; import com.paraware.domain.Parent; public class TestHibernate { public static void main(String args[]) throws HibernateException, SQLException { SessionFactory sessionFactory; Transaction transaction; Configuration cfg = new Configuration(); cfg.addClass(Parent.class); cfg.addClass(Child.class); sessionFactory = cfg.buildSessionFactory(); Session session = sessionFactory.openSession(); transaction = session.beginTransaction(); Parent newUser = new Parent(); newUser.setUserID("bnnn"); newUser.setUserName("Vivi"); newUser.setPassword("abcff"); newUser.setEmailAddress("vi...@co..."); newUser.setLastLogon(new Date()); session.save(newUser); Child ms1 = new Child(); ms1.setName("Mickey"); Child ms2 = new Child(); ms2.setName("Mouse"); Set mouseSet = new HashSet(); mouseSet.add(ms1); mouseSet.add(ms2); //set up association newUser.setChildren(mouseSet); //save foreign keys ms1.setParent(newUser); ms2.setParent(newUser); transaction.commit(); // close our session and release resources session.flush(); session.close(); } } --------------------------------------------------------------------- JIRA INFORMATION: This message is automatically generated by JIRA. If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira |