【发布时间】:2015-09-18 00:07:12
【问题描述】:
我有一个带有 jpa、ejb、backingbean、jsp 的结构。我能够查询数据库并将结果返回到页面,但是当我尝试合并(更新)ejb 时它不起作用。没有错误,但它不会更新值。为了测试,我只是硬编码了这些值。如果您能告诉我我在做什么,我将不胜感激:
jpa:
package com.ray.adtf.jpa;
import java.io.Serializable;
import javax.persistence.*;
/**
* The persistent class for the GRIDWEIGHT database table.
*
*/
@Entity
@NamedQueries({
@NamedQuery(name="Gridweight.findAll", query="SELECT g FROM Gridweight g"),
@NamedQuery(name = "Gridweight.findByGridid", query = "SELECT g FROM Gridweight g WHERE g.gridid = :gridid")
})
public class Gridweight implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private long gridid;
private String checking;
private String drawing;
private String modeling;
@Column(name="\"RELEASE\"")
private String release;
private String structural;
private String thermal;
public Gridweight() {
}
public long getGridid() {
return this.gridid;
}
public void setGridid(long gridid) {
this.gridid = gridid;
}
public String getChecking() {
return this.checking;
}
public void setChecking(String checking) {
this.checking = checking;
}
public String getDrawing() {
return this.drawing;
}
public void setDrawing(String drawing) {
this.drawing = drawing;
}
public String getModeling() {
return this.modeling;
}
public void setModeling(String modeling) {
this.modeling = modeling;
}
public String getRelease() {
return this.release;
}
public void setRelease(String release) {
this.release = release;
}
public String getStructural() {
return this.structural;
}
public void setStructural(String structural) {
this.structural = structural;
}
public String getThermal() {
return this.thermal;
}
public void setThermal(String thermal) {
this.thermal = thermal;
}
}
ejb:
package com.ray.adtf.ejb;
import com.ray.adtf.jpa.Gridweight;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import java.math.BigInteger;
import java.util.List;
@Stateless
public class GridWeightBean {
@PersistenceContext
private EntityManager em;
public void updWeight(Gridweight gridweight) {
em.merge(gridweight);
}
public Gridweight getGridweight(Integer vgridid) {
return em.createQuery("FROM Gridweight where gridid = "+ vgridid, Gridweight.class).getSingleResult();
}
}
支持 bean:
package com.ray.adtf.web;
import javax.faces.bean.ManagedBean;
import javax.ejb.EJB;
import com.ray.adtf.ejb.*;
import com.ray.adtf.jpa.Gridweight;
@ManagedBean
public class gridWeight {
@EJB
private GridWeightBean ejb;
public Gridweight getGridWeight( int vgridid) {
Gridweight weight1 = ejb.getGridweight(vgridid);
return weight1;
}
public String updWeight() {
Gridweight gw = ejb.getGridweight(2);
gw.setGridid(2);
gw.setDrawing("99");
ejb.updWeight(gw);
return null;
}
}
谢谢!!!
【问题讨论】:
-
不确定它没有显示 jsp 代码,但它是:
-
能否提供 backingbean 代码?
-
不确定为什么 backing bean 没有发布......任何帮助都会非常感谢您
标签: jpa sql-update ejb