Hibernate 报错希望高手给予指点

jack0603 2009-05-20 11:00:15
请高手给我指点

Action中插入数据代码
	        
tblsb.setSalesbusinessid(saleDetailsForm.getSalesbusinessid());
tblsb.setTitle(saleDetailsForm.getTitle());
tblsb.setBegindate(getdate.getFormatOracleDate(saleDetailsForm.getBegindate()));
tblsb.setEnddate(getdate.getFormatOracleDate(saleDetailsForm.getEnddate()));
tblsb.setContent(saleDetailsForm.getContent());
tblsb.setSalespeopleid(saleDetailsForm.getSalespeopleid());
tblsb.setCustomerid(saleDetailsForm.getCustomerid());
tblsb.setCreateuserid(saleDetailsForm.getCreateuserid());
tblsb.setCreatedate(getdate.getFormatOracleDate(saleDetailsForm.getCreatedate()));
//tblsb.setTblsalepeople(salepeople);


spioperate.update(salebusiness);


package com.nicebridge.hcss.crm.hibernate.pojo;

import java.io.Serializable;
import java.util.Date;

public class TblSalesbusiness implements Serializable{
private String salesbusinessid;
private String title;
private Date begindate;
private Date enddate;
private String content;
private String salespeopleid;
private String customerid;
private String createuserid;
private Date createdate;
private TblSalepeople tblsalepeople;


public String getSalesbusinessid() {
return salesbusinessid;
}
public void setSalesbusinessid(String salesbusinessid) {
this.salesbusinessid = salesbusinessid;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Date getBegindate() {
return begindate;
}
public void setBegindate(Date begindate) {
this.begindate = begindate;
}
public Date getEnddate() {
return enddate;
}
public void setEnddate(Date enddate) {
this.enddate = enddate;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getSalespeopleid() {
return salespeopleid;
}
public void setSalespeopleid(String salespeopleid) {
this.salespeopleid = salespeopleid;
}
public String getCustomerid() {
return customerid;
}
public void setCustomerid(String customerid) {
this.customerid = customerid;
}
public String getCreateuserid() {
return createuserid;
}
public void setCreateuserid(String createuserid) {
this.createuserid = createuserid;
}
public Date getCreatedate() {
return createdate;
}
public void setCreatedate(Date createdate) {
this.createdate = createdate;
}
public TblSalepeople getTblsalepeople() {
return tblsalepeople;
}
public void setTblsalepeople(TblSalepeople tblsalepeople) {
this.tblsalepeople = tblsalepeople;
}

}


插入数据库方法

public void update(Object object){
Session session = sessionFactory.openSession();
Transaction tran = session.beginTransaction();
session.update(object);
tran.commit();
}




<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.nicebridge.hcss.crm.hibernate.pojo.TblSalesbusiness" table="TBL_SALESBUSINESS" schema="SCOTT">
<id name="salesbusinessid" type="java.lang.String">
<column name="SALESBUSINESSID" length="50" />
<generator class="assigned" />
</id>
<property name="title" type="java.lang.String">
<column name="TITLE" length="100" not-null="true" />
</property>
<property name="begindate" type="java.util.Date">
<column name="BEGINDATE" length="7" />
</property>
<property name="enddate" type="java.util.Date">
<column name="ENDDATE" length="7" />
</property>
<property name="content" type="java.lang.String">
<column name="CONTENT" length="500" not-null="true" />
</property>
<property name="salespeopleid" type="java.lang.String">
<column name="SALESPEOPLEID" length="50" not-null="true" />
</property>
<property name="customerid" type="java.lang.String">
<column name="CUSTOMERID" length="50" not-null="true" />
</property>
<property name="createuserid" type="java.lang.String">
<column name="CREATEUSERID" length="50" not-null="true" />
</property>
<property name="createdate" type="java.util.Date">
<column name="CREATEDATE" length="7" not-null="true" />
</property>

<many-to-one name="tblsalepeople" column="salespeopleid" class="com.nicebridge.hcss.crm.hibernate.pojo.TblSalepeople" cascade="all" outer-join="true" />

</class>
</hibernate-mapping>






...全文
338 点赞 收藏 24
写回复
24 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
yangyawei2011 2011-08-11
一群sb,没有一个回答问题的
回复
daerqwert 2009-06-03
很明显报错是有重复的列名。。楼上有2个兄弟已经把问题说得很明确了。
回复
SW13968086129 2009-06-02
我在用EJB3的时候也碰到这样的情况,我更新操作是:
用主键LOAD对象(该对象存在),然后对该对象赋需要改变的值,然后在update提交给服务器的时候就出现和楼主一样的错误了。
期待高手解决啊!
回复
apple_hgp 2009-05-26
关注中.......
回复
zhangli_86 2009-05-26
没看懂,那好像不是插入数据库的方法啊
回复
xu54647265 2009-05-26
插入的方法应该是SAVE吧?……
回复
zm_hs 2009-05-26
你是修改还是插入啊!都没弄明白
回复
APOLLO_TS 2009-05-26
哇!!写的好规范呀!!
<property name="salespeopletypeid" type="java.lang.String">
<column name="SALESPEOPLETYPEID" length="50" not-null="true" />
</property>
<many-to-one name="tblsalespeopletype" column="salespeopletypeid"

---------------------------------------------------------------------------------------------

<many-to-one name="tblsalespeopletype" class="类的全路径" fetch="select">
<column name="salespeopletypeid" not-null="true"--要不要看情况 unique="true"--要不要看情况>
<comment>注释写上</comment>
</column>
</many-to-one>
回复
天边星斗 2009-05-26
javax.servlet.ServletException: org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update


这儿提示你不能更新,你得从这句入手。
首先数据更新你要能读出。读出呢主键就不用在给值,
主键也不能更改。更改别的数据。用断点看你的sql 语句是否正确。
根据这个思路你就可以解决的。
回复
l_wenb 2009-05-26
bang up
回复
qiheia 2009-05-26
ORA-00957: 重复的列名
我没猜错的话,应该是跟数据库中哪条记录的主键重复了。。。。。。
回复
lvsh870228 2009-05-25
1 tblsb.setSalesbusinessid(saleDetailsForm.getSalesbusinessid());
2 tblsb.setTitle(saleDetailsForm.getTitle());
3 tblsb.setBegindate(getdate.getFormatOracleDate(saleDetailsForm.getBegindate()));
4 tblsb.setEnddate(getdate.getFormatOracleDate(saleDetailsForm.getEnddate()));
5 tblsb.setContent(saleDetailsForm.getContent());
6 tblsb.setSalespeopleid(saleDetailsForm.getSalespeopleid());
7 tblsb.setCustomerid(saleDetailsForm.getCustomerid());
8 tblsb.setCreateuserid(saleDetailsForm.getCreateuserid());
1,7一样的
回复
cjg520jie 2009-05-21
列名重复,log上说的很明白啊
回复
APOLLO_TS 2009-05-21
根据主键LOAD实体。然后更新!
如果不能Load实体。是不能更新的。

其次主键状态很重要。

回复
beijingpz 2009-05-21
TblSalepeople代码贴出来
回复
ndcs_dhf2008 2009-05-21
其实问题很简单,仔细点就可以找到,出错这么明显.
回复
ty_seven 2009-05-21
<property name="employeeno" type="java.lang.String">
<column name="EMPLOYEENO" length="50" not-null="true" />
</property>
<many-to-one name="tblemployee" class="com.nicebridge.hcss.crm.hibernate.pojo.TblEmployee" update="true" column="employeeno" cascade="all" unique="true" />
你的2个column都是employeeno

<property name="salespeopletypeid" type="java.lang.String">
<column name="SALESPEOPLETYPEID" length="50" not-null="true" />
</property>
<many-to-one name="tblsalespeopletype" column="salespeopletypeid" class="com.nicebridge.hcss.crm.hibernate.pojo.TblSalespeopletype" update="true" cascade="all" outer-join="true"/>
你的2个column都是salespeopletypeid
回复
fiagfiaehi 2009-05-21
深圳JAVA J2EE QQ①群 32763598 深圳JAVA J2EE QQ②群 6086837
欢迎深圳的JAVA程序员加入,共同探讨技术与工作、项目合作、共享信息、结交朋友
加入请输入验证信息:SZJP
回复
jack0603 2009-05-21

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.nicebridge.hcss.crm.hibernate.pojo.TblSalepeople" table="TBL_SALEPEOPLE" schema="SCOTT">
<id name="salespeopleid" type="java.lang.String">
<column name="SALESPEOPLEID" length="50" />
<generator class="assigned" />
</id>
<property name="employeeno" type="java.lang.String">
<column name="EMPLOYEENO" length="50" not-null="true" />
</property>
<property name="salespeopletypeid" type="java.lang.String">
<column name="SALESPEOPLETYPEID" length="50" not-null="true" />
</property>
<property name="business" type="java.lang.String">
<column name="BUSINESS" length="200" />
</property>

<many-to-one name="tblemployee" class="com.nicebridge.hcss.crm.hibernate.pojo.TblEmployee" update="true" column="employeeno" cascade="all" unique="true" />

<many-to-one name="tblsalespeopletype" column="salespeopletypeid" class="com.nicebridge.hcss.crm.hibernate.pojo.TblSalespeopletype" update="true" cascade="all" outer-join="true"/>


</class>
</hibernate-mapping>




package com.nicebridge.hcss.crm.hibernate.pojo;

import java.io.Serializable;

public class TblSalepeople implements Serializable{
private String salespeopleid;
private String employeeno;
private String salespeopletypeid;
private String business;
private TblEmployee tblemployee;
private TblSalespeopletype tblsalespeopletype;

public String getSalespeopleid() {
return salespeopleid;
}
public void setSalespeopleid(String salespeopleid) {
this.salespeopleid = salespeopleid;
}
public String getEmployeeno() {
return employeeno;
}
public void setEmployeeno(String employeeno) {
this.employeeno = employeeno;
}
public String getSalespeopletypeid() {
return salespeopletypeid;
}
public void setSalespeopletypeid(String salespeopletypeid) {
this.salespeopletypeid = salespeopletypeid;
}
public String getBusiness() {
return business;
}
public void setBusiness(String business) {
this.business = business;
}

public TblEmployee getTblemployee() {
return tblemployee;
}
public void setTblemployee(TblEmployee tblemployee) {
this.tblemployee = tblemployee;
}
public TblSalespeopletype getTblsalespeopletype() {
return tblsalespeopletype;
}
public void setTblsalespeopletype(TblSalespeopletype tblsalespeopletype) {
this.tblsalespeopletype = tblsalespeopletype;
}
}


回复
bear13 2009-05-21
删除 tblsb.setSalesbusinessid(saleDetailsForm.getSalesbusinessid());

执行更新操作,主键不用再set....

回复
加载更多回复
相关推荐
发帖
Java EE
创建于2007-09-28

6.6w+

社区成员

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
申请成为版主
帖子事件
创建了帖子
2009-05-20 11:00
社区公告
暂无公告