Hi,I have two tables called author and booksinfo.my xml files are as follows:
author.hbm.xml
......
<id name="authorID"
column="AuthorID" type="string" length="10">
<generator class="assigned">
</generator>
</id>
<property name="usrname">
<column name="Name" not-null="false" sql-type="varchar(30)"/>
</property>
</class>
bookinfo.hbm.xml
......
<class name="demo.bookinfo" table="booksinfo">
<id column="authorID" name="authorid" type="string" length="10">
<generator class="assigned">
</generator>
</id>
<one-to-one cascade="all" class="demo.author" name="author" constrained="true"/>
<property name="isbn">
<column name="isbn" not-null="false" sql-type="varchar(10)"/>
</property>
<property name="price">
<column name="Price" not-null=" true" sql-type="varchar(10)"/>
</property>
......
my
test file is:
.....
SessionFactory sessions = conf.buildSessionFactory();
Session s = sessions.openSession();
Transaction tx = s.beginTransaction();
author a = new author();
a.setAuthorID("1");
a.setusrname("liuyan");
//s.save(a);
bookinfo b = new bookinfo();
b.setAuthorid("1");
b.setIsbn("1");
b.setPrice("4");
b.setAuthor(a);
s.save(b);
tx.commit();
.....
When I try to run it it gives me an HibernateException: SQL insert, update or delete failed (row not found)error.
Could anybody tell me how to resolve this problem? thanks a million.
By the way my bookinfo.java is as follows:
package demo;
public class bookinfo {
private author author;
private
String isbn;
private String price;
private String authorid;
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public author getAuthor() {
return author;
}
public void setAuthor(author author) {
this.author = author;
}
public String getAuthorid() {
return authorid;
}
public void setAuthorid(String authorid) {
this.authorid = authorid;
}}
my author.java is as follows:
package demo;
import java.io.Serializable;
public class author implements java.io.Serializable{
private String usrname;
private String id;
public String getAuthorID(){
return id;
}
public void setAuthorID(String authorID) {
id=authorID;
}
public String getusrname() {
return usrname;
}
public void setusrname(String usrname) {
this.usrname = usrname;
}}
I do not think I missed any row in my codes :'(
Please help me.