[200 points] hibernate query associated problems solved immediately to the point!

Category: Java Related
 
zhang8166835
2013-08-19 01:30:57

Sponsored Links
Table I: userinfo
uid int (3) user ID
uname varchar (20) Username
passwd varchar (20) user password
eid int (3) unsigned employee number
PRIMARY KEY (uid)
Table II: emp
id int (3) Employee Number
name varchar (20) ; employee name
address varchar (20) Employee Address
PRIMARY KEY (id)
I want to query tables one of the data, the employee number of employees with a table name instead of two, and if so, I have to be specified in Userinfo_Bean.hbm.xml
many-to-one, Emp_Bean.hbm.xml specified one- to-many
can I do in these two documents which add nothing, but directly in the HQL statement specifies the association do?

such as: sql = "select A . uid, A.uname, A.passwd, B.name from Userinfo_Bean A, Emp_bean B where A.eid = B.id and B.name like? and B. address like? ";
Configuration cfg = new Configuration (). addClass (Userinfo_Bean.class);
SessionFactory sessions = cfg.buildSessionFactory ();
Session session = sessions.openSession ();
Query query = ; session.createQuery (sql);
List list = query.list ();

I write this, the system being given, ask the experts, so you can use?
given as follows:
StandardWrapperValve [debugjsp]: Servlet.service () for servlet debugjsp threw exception
javax.servlet . ServletException: in expected: B [select A.uid, A.uname, A.passwd, B.name from hibernate.Userinfo_Bean A, Hello_bean B where A.eid = B.id and B.name like? and B.address like?]
javax.servlet.ServletException: in expected: B [select A. uid, A.uname, A.passwd, B.name from hibernate.Userinfo_Bean A, Hello_bean B where A.eid = B.id and B.name like? and B . address like?]
at org.apache.jasper.runtime.PageContextImpl.handlePageException (PageContextImpl.java: 471)
at org.apache.jsp.userinfo $ jsp._jspService (userinfo $ jsp.java: 185)
at org.apache.jasper.runtime.HttpJspBase.service (HttpJspBase.java: 107)
at javax.servlet.http.HttpServlet.service (HttpServlet.java : 853)
at org.apache.jasper.servlet.JspServlet $ JspServletWrapper.service (JspServlet.java: 201)
at org.apache.jasper.servlet.JspServlet.serviceJspFile (JspServlet.java : 381)
at org.apache.jasper.servlet.JspServlet.service (JspServlet.java: 473)
at javax.servlet.http.HttpServlet.service (HttpServlet.java: 853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java: 247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java: 193)
at org.apache.catalina.core.StandardWrapperValve.invoke (StandardWrapperValve.java: 243)
at org.apache.catalina.core.StandardPipeline.invokeNext (StandardPipeline.java: 566)
at ; org.apache.catalina.core.StandardPipeline.invoke (StandardPipeline.java: 472)
at org.apache.catalina.core.ContainerBase.invoke (ContainerBase.java: 943)
at org . apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java: 190)
at org.apache.catalina.core.StandardPipeline.invokeNext (StandardPipeline.java: 566)
at org.apache . catalina.valves.CertificatesValve.invoke (CertificatesValve.java: 246)
at org.apache.catalina.core.StandardPipeline.invokeNext (StandardPipeline.java: 564)
at org.apache.catalina . core.StandardPipeline.invoke (StandardPipeline.java: 472)
at org.apache.catalina.core.ContainerBase.invoke (ContainerBase.java: 943)
at org.apache.catalina.core . StandardContext.invoke (StandardContext.java: 2347)
at org.apache.catalina.core.StandardHostValve.invoke (StandardHostValve.java: 180)
at org.apache.catalina.core.StandardPipeline . invokeNext (StandardPipeline.java: 566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke (ErrorDispatcherValve.java: 170)
at org.apache.catalina.core.StandardPipeline.invokeNext (StandardPipeline.java: 564)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java: 170)
at org.apache.catalina.core.StandardPipeline.invokeNext (StandardPipeline . java: 564)
at org.apache.catalina.core.StandardPipeline.invoke (StandardPipeline.java: 472)
at org.apache.catalina.core.ContainerBase.invoke (ContainerBase.java : 943)
at org.apache.catalina.core.StandardEngineValve.invoke (StandardEngineValve.java: 174)
at org.apache.catalina.core.StandardPipeline.invokeNext (StandardPipeline.java: 566 )
at org.apache.catalina.core.StandardPipeline.invoke (StandardPipeline.java: 472)
at org.apache.catalina.core.ContainerBase.invoke (ContainerBase.java: 943)
at org.apache.catalina.connector.http.HttpProcessor.process (HttpProcessor.java: 1027)
at org.apache.catalina.connector.http.HttpProcessor.run (HttpProcessor.java: 1125 )
at java.lang.Thread.run (Thread.java: 534)


Sponsored Links

jhyrfdsdf6
2013-08-19 01:43:04
brackets should be added to the package name, such as: com.packagename. Userinfo_Bean.class
Configuration cfg = new Configuration (). addClass (yourpackagename.Userinfo_Bean.class). addClass (yourpackagename.Emp_Bean);
SessionFactory sf = cfg.buildSessionFactory ();
Rung_zhengzhiwu
2013-08-19 01:46:02
lvyg () Hello
or not! Given as follows:
javax.servlet.ServletException: in expected: B [select A.uid, A.uname, A.passwd, B.name from hibernate.Userinfo_Bean A, Hello_bean B where A.eid = B.id and B.name like? and B.address like?]
javax.servlet.ServletException: in ; expected: B [select A.uid, A.uname, A.passwd, B.name from hibernate.Userinfo_Bean A, Hello_bean B where A.eid = B.id and B.name like? and B.address like?]
at org.apache.jasper.runtime.PageContextImpl.handlePageException (PageContextImpl.java: 471)
at org . apache.jsp.userinfo $ jsp._jspService (userinfo $ jsp.java: 185)
at org.apache.jasper.runtime.HttpJspBase.service (HttpJspBase.java: 107)
at javax . servlet.http.HttpServlet.service (HttpServlet.java: 853)
at org.apache.jasper.servlet.JspServlet $ JspServletWrapper.service (JspServlet.java: 201)
at org.apache . jasper.servlet.JspServlet.serviceJspFile (JspServlet.java: 381)
at org.apache.jasper.servlet.JspServlet.service (JspServlet.java: 473)
at javax.servlet.http . HttpServlet.service (HttpServlet.java: 853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java: 247)
at org.apache.catalina.core.ApplicationFilterChain . doFilter (ApplicationFilterChain.java: 193)
at org.apache.catalina.core.StandardWrapperValve.invoke (StandardWrapperValve.java: 243)
at org.apache.catalina.core.StandardPipeline.invokeNext (StandardPipeline.java: 566)
at org.apache.catalina.core.StandardPipeline.invoke (StandardPipeline.java: 472)
at org.apache.catalina.core.ContainerBase.invoke (ContainerBase . java: 943)
at org.apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java: 190)
at org.apache.catalina.core.StandardPipeline.invokeNext (StandardPipeline.java : 566)
at org.apache.catalina.valves.CertificatesValve.invoke (CertificatesValve.java: 246)
at org.apache.catalina.core.StandardPipeline.invokeNext (StandardPipeline.java: 564 )
at org.apache.catalina.core.StandardPipeline.invoke (StandardPipeline.java: 472)
at org.apache.catalina.core.ContainerBase.invoke (ContainerBase.java: 943)
at org.apache.catalina.core.StandardContext.invoke (StandardContext.java: 2347)
at org.apache.catalina.core.StandardHostValve.invoke (StandardHostValve.java: 180)
at org.apache.catalina.core.StandardPipeline.invokeNext (StandardPipeline.java: 566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke (ErrorDispatcherValve.java: 170)
at ; org.apache.catalina.core.StandardPipeline.invokeNext (StandardPipeline.java: 564)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java: 170)
at org . apache.catalina.core.StandardPipeline.invokeNext (StandardPipeline.java: 564)
at org.apache.catalina.core.StandardPipeline.invoke (StandardPipeline.java: 472)
at org.apache . catalina.core.ContainerBase.invoke (ContainerBase.java: 943)
at org.apache.catalina.core.StandardEngineValve.invoke (StandardEngineValve.java: 174)
if to say Hello_bean corresponding alias B have a problem!
hljupolymer
2013-08-19 01:49:54
the eid emd table as a foreign key.
user.hbm.xml
<? xml version = "1.0"?>
<! DOCTYPE hibernate-mapping PUBLIC
"- / / Hibernate / Hibernate Mapping DTD 2.0 / / EN"
"

<hibernate-mapping>
<! -
Created by the Middlegen Hibernate plugin 2.1

->

<class
name = "com.hibernate.Userinfo"
table = "userinfo"
>

<id
name = "uid"
; type = "java.lang.Long"
column = "uid"
;>
<generator class="native" />
</id>

<property
name = " name "
type =" java.lang.String "
column = "name"
not-null = "true"
length = "100"
/>
<property
name = "passwd"
type = "java.lang.String"
column = "passwd"
not-null = " true "
length =" 100 "
/>

<! - Associations ->

<! - bi -directional many-to-one association to Emp ->
<many-to-one
name = "emp"
class = "com.hibernate.Emp"
not-null = "true"
>
<column name="eid" />
</ many-to-one>

</class>
</ hibernate-mapping>

<? xml version = "1.0"?>
<! DOCTYPE hibernate- mapping PUBLIC
"- / / Hibernate / Hibernate Mapping DTD 2.0 / / EN"
"

<hibernate-mapping>
<! -
Created by the Middlegen Hibernate plugin 2.1

->

< ; class
name = "com.hibernate.Emp"
table = "emp"
> ;

<id
name = "eid"
type = "java.lang.Long"
column = " eid "
>
<generator class="native" /> ;
</id>

<property
; name = "name"
type = "int"
; column = "name"
not-null = "true"
; length = "20"
/>
<property
name = "address"
type = "java . lang.String "
column =" address "
; not-null = "true"
length = "20"
/>

<! - Associations ->

< ;! - bi-directional one-to-many association to Userinfo ->
<set
; name = "userinfos"
lazy = "true"
; inverse = "true"
cascade = "none"
>
; <key>
<column name = "eid" />
</key>
; <one-to-many
class = "com.hibernate.Userinfo" ;
/>
</set>

< ;/ class>
</ hibernate-mapping>
zhangshuaixing1234
2013-08-19 02:05:14
from userinfo a, emp b where a.eid = b.id

Recommended Hibernate8IDE (Console) this tool to test your HQL
shuaisam
2013-08-19 02:22:09
in a page how to call it
jiaque_0824
2013-08-19 02:31:31
Or you directly sql query, the result deal with their own, with a hibernate on the with his thoughts, your userinfo and how emp class definition, do userinfo which do not contain a reference to emp, any value is not directly on the line
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.