|
From: <leg...@at...> - 2003-06-10 03:09:40
|
Message:
The following issue has been closed.
Resolver: Gavin King
Date: Mon, 9 Jun 2003 10:07 PM
unsaved-value="null" is not sensible for assigned ids. Please do NOT report bugs in user code here. JIRA is for bugs in *Hibernate*. TIA
---------------------------------------------------------------------
View the issue:
http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-125
Here is an overview of the issue:
---------------------------------------------------------------------
Key: HB-125
Summary: generator class="assigned", when used in parent-children model's child class
Type: Bug
Status: Closed
Priority: Major
Resolution: REJECTED
Project: Hibernate2
Components:
core
Versions:
2.0 final
Assignee: Gavin King
Reporter: neil yang
Created: Sun, 8 Jun 2003 10:27 PM
Updated: Mon, 9 Jun 2003 10:07 PM
Environment: windows xp
Description:
I have two class: Company & Person, they're Parent-children relation-ship. the 2 classes' id are all "assigned", beacause in an other true development env., I had to use programatic "assigned" id. When I run the test code, the exception thrown.
package h;
import java.util.ArrayList;
import java.util.Date;
public class Company {
static int _lastID = 100;
String id;
public void setId(String value) {
this.id=value;
}
public String getId() {
return id;
}
String name;
public void setName(String value) {
this.name=value;
}
public String getName() {
return name;
}
ArrayList partners = new ArrayList();
public String[] getMyPartners(){
return (String[])partners.toArray(new String[partners.size()]);
}
public void setMyPartners(String[] parts){
partners.clear();
for(int i=0; i<parts.length; i++){
partners.add(parts[i]);
}
}
java.util.Date createdDate;
public void setCreatedDate(Date d ){
this.createdDate = d;
}
public Date getCreatedDate(){
return this.createdDate;
}
java.util.List employees=new java.util.ArrayList();
public void setEmployees(java.util.List value) {
this.employees=value;
}
public java.util.List getEmployees() {
return employees;
}
public void addEmployee(h.Person value) {
employees.add(value);
}
public void removeEmployee(h.Person value) {
employees.remove(value);
}
public void clearEmployees() {
employees.clear();
}
private boolean _registered;
public boolean getRegistered(){
return this._registered;
}
public void setRegistered(boolean val){
this._registered = val;
}
}
Company.hbm.xml:
<?xml version="1.0" encoding="GB2312"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class name="h.Company">
<id name = "id" unsaved-value = "null">
<generator class="assigned"/>
</id>
<property name="name"/>
<property name="myPartners" type="serializable" />
<property name="registered" type="boolean"/>
<bag name="employees" cascade="all">
<key column="company_id"/>
<one-to-many class="h.Person"/>
</bag>
</class>
</hibernate-mapping>
package h;
import java.io.Serializable;
public class Person implements Serializable{
public static int _lastID = 1000;
String name;
/**
Sets the value of field name.
@param name value of field name
*/
public void setName(String value) {
this.name=value;
}
/**
Gets the value of field name.
@return value of field name
*/
public String getName() {
return name;
}
String address;
/**
Sets the value of field address.
@param address value of field address
*/
public void setAddress(String value) {
this.address=value;
}
/**
Gets the value of field address.
@return value of field address
*/
public String getAddress() {
return address;
}
String id ;
/**
Sets the value of field id.
@param id value of field id
*/
public void setId(String value) {
this.id=value;
}
/**
Gets the value of field id.
@return value of field id
*/
public String getId() {
return id;
}
}
Person.hbm.xml:
<?xml version="1.0" encoding="GB2312"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class name="h.Person">
<id name = "id" unsaved-value = "null">
<generator class="assigned"/>
</id>
<property name="name"/>
<property name="address"/>
</class>
</hibernate-mapping>
the Test code is:
package h;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Query;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
import java.util.List;
import java.util.Iterator;
class TestCompany
{
private static SessionFactory sessions;
public static void main(String[] args) throws Exception
{
String[] partners = {
"IBM",
"Microsoft",
"Lenovo",
"Apple"
};
Configuration conf = new Configuration()
.addClass(Person.class)
.addClass(Company.class);
SchemaExport dbExport = new SchemaExport(conf);
dbExport.setOutputFile("sql.txt");
dbExport.create(true, true);
sessions = conf.buildSessionFactory();
//start......
Session s = sessions.openSession();
Transaction t = s.beginTransaction();
Company c = new Company();
c.setName("UFSoft Company Ltd.");
c.setMyPartners(partners);
c.setRegistered(true);
Person p1 = new Person();
p1.setId(String.valueOf(Person._lastID++));
p1.setName("Liuto");
p1.setAddress("Beijing Haidian");
Person p2 = new Person();
p2.setId(String.valueOf(Person._lastID++));
p2.setName("sun");
p2.setAddress("beijing shangdi");
c.addEmployee(p1);
c.addEmployee(p2);
c.setId(String.valueOf(Company._lastID++));
//c.setId(Company._lastID++);
s.save(c);
s.flush();
t.commit();
s.close();
sessions.close();
}
}
when flush(), the bug reported:
net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:611)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:580)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:27)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2073)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2046)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:1989)
at h.TestCompany.main(TestCompany.java:115)
---------------------------------------------------------------------
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/Administrators.jspa
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
|