Hallo zusammen,
ich kämpfe mal wieder mit den ach so schönen Enterprise Java Beans 3.0 und JPA.
Mein Problem ist, dass eine DB-Abfrage über den Fremdschlüssel folgende Exception bringt.
Zu eurem besseren Verständnis nachfolgend der Code:
Entitybeans:
Sessionbean
Servlet
Hoffe jemand von euch kennt sich damit aus.
Cullen
ich kämpfe mal wieder mit den ach so schönen Enterprise Java Beans 3.0 und JPA.
Mein Problem ist, dass eine DB-Abfrage über den Fremdschlüssel folgende Exception bringt.
javax.ejb.EJBException: java.lang.IllegalArgumentException: You have attempted to set a parameter value using a name of landid that does not exist in the query string select o from FvFirma o where o.land = :land.; nested exception is:
java.lang.IllegalArgumentException: You have attempted to set a parameter value using a name of landid that does not exist in the query string select o from FvFirma o where o.land = :land.; nested exception is: oracle.oc4j.rmi.OracleRemoteException: java.lang.IllegalArgumentException: You have attempted to set a parameter value using a name of landid that does not exist in the query string select o from FvFirma o where o.land = :land.; nested exception is:
java.lang.IllegalArgumentException: You have attempted to set a parameter value using a name of landid that does not exist in the query string select o from FvFirma o where o.land = :land.
oracle.oc4j.rmi.OracleRemoteException: java.lang.IllegalArgumentException: You have attempted to set a parameter value using a name of landid that does not exist in the query string select o from FvFirma o where o.land = :land.
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.1.1) ].server.ejb.EJBUtils.getUserException(EJBUtils.java:346)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.1.1) ].server.ejb.interceptor.system.AbstractTxInterceptor.convertAndHandleMethodException(AbstractTxInterceptor.java:69)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.1.1) ].server.ejb.interceptor.system.TxRequiredInterceptor.invoke(TxRequiredInterceptor.java:52)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.1.1) ].server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.1.1) ].server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.1.1) ].server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.1.1) ].server.ejb.InvocationContextPool.invoke(InvocationContextPool.java:55)
at com.evermind[Oracle Containers for J2EE 10g (10.1.3.1.1) ].server.ejb.StatelessSessionEJBObject.OC4J_invokeMethod(StatelessSessionEJBObject.java:87)
at Logic_RemoteProxy_27ip3jg.findByLandId(Unknown Source)
Zu eurem besseren Verständnis nachfolgend der Code:
Entitybeans:
Code:
/******Firma*******/
@Entity
@NamedQueries({
@NamedQuery(name = "FvFirma.findAll", query = "select o from FvFirma o"),
@NamedQuery(name = "FvFirma.findByLandId",
query = "select o from FvFirma o where o.land = :land")
})
@Table(name = "FV_FIRMA")
public class FvFirma implements Serializable {
private Long fid;
private String fname;
private String stadtname;
private Land land;
public FvFirma() {
}
@Id
@SequenceGenerator(name="SQ_FV_FIRMA_GEN", sequenceName="SQ_FV_FIRMA", allocationSize=1)
@Column(name="FID", nullable = false)
public Long getFid() {
return fid;
}
public void setFid(Long fid) {
this.fid = fid;
}
@Column(nullable = true)
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getStadtname() {
return stadtname;
}
public void setStadtname(String stadtname) {
this.stadtname = stadtname;
}
@ManyToOne
@JoinColumn(name="LANDID")
public Land getLand() {
return land;
}
public void setLand(Land land) {
this.land = land;
}
public String toString() {
return "Firma [" +fid+ "] " +fname+ ", " +stadtname;
}
}
/******Land******/
@Entity
@NamedQueries({
@NamedQuery(name = "Land.findAll", query = "select o from Land o"),
@NamedQuery(name = "Land.findByPK", query = "select o from Land o where o.landid = :landid")
})
@Table(name = "LAND")
public class Land implements Serializable {
private String landid;
private String landname;
private List<FvFirma> fvFirmaList;
public Land() { }
public Land(String landid, String landname) {
this.landid = landid;
this.landname = landname;
fvFirmaList = new LinkedList<FvFirma>();
}
@Id
@Column(name = "LANDID", nullable = false)
public String getLandid() {
return landid;
}
public void setLandid(String landid) {
this.landid = landid;
}
@Column(nullable = false)
public String getLandname() {
return landname;
}
public void setLandname(String landname) {
this.landname = landname;
}
@OneToMany(mappedBy = "land")
public List<FvFirma> getFvFirmaList() {
return fvFirmaList;
}
public void setFvFirmaList(List<FvFirma> fvFirmaList) {
this.fvFirmaList = fvFirmaList;
}
public FvFirma addFvFirma(FvFirma fvFirma) {
getFvFirmaList().add(fvFirma);
fvFirma.setLand(this);
return fvFirma;
}
public FvFirma removeFvFirma(FvFirma fvFirma) {
getFvFirmaList().remove(fvFirma);
fvFirma.setLand(null);
return fvFirma;
}
public String toString() {
String firmen = "";
return "Land ["+landid+"] = " +landname;
}
}
Sessionbean
Code:
@Stateless(name="Logic")
public class LogicBean implements LogicBeanRemote, LogicBeanLocal {
@PersistenceContext(unitName="fhinfo")
private EntityManager em;
public LogicBean() {
}
/** <code>select o from FvFirma o</code> */
public List<FvFirma> queryFvFirmaFindAll() {
return em.createNamedQuery("FvFirma.findAll").getResultList();
}
public List<Land> queryLandFindAll() {
return em.createNamedQuery("Land.findAll").getResultList();
}
public Land findLandByPK(String lid) {
return (Land) em.createNamedQuery("Land.findByPK")
.setParameter("landid", lid)
.getSingleResult();
}
public List<FvFirma> findByLandId(String landid) {
return em.createNamedQuery("FvFirma.findByLandId")
.setParameter("land", landid)
.getResultList();
}
}
Code:
public class WebClient extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=windows-1252";
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
try {
Context context = new InitialContext();
LogicBeanRemote lbr = (LogicBeanRemote) context.lookup("Logic");
out.println("<html>");
out.println("<head><title>WebEJBClient</title></head>");
out.println("<body>");
List<FvFirma> flist = lbr.findByLandId("de");
for(FvFirma temp : flist) {
out.println(temp.toString() + "<br>");
}
out.println("</body></html>");
out.close();
}
catch(NamingException nec) {
nec.printStackTrace();
}
}
}
Hoffe jemand von euch kennt sich damit aus.
Cullen
Zuletzt bearbeitet: