Hi all,
I'm getting in trouble while executing a simple query. I have an Entity named
"Project", and a Session named ProjectServiceBean that implements
ProjectService interface.
So the ProjectService (remote interface) gives me a method like this:
| public Project findByName(String name) throws RemoteException {
| return (Project)entityManager.createQuery("from Project p where
p.name = name").getSingleResult();
| }
|
Into my table "PROJECT" I don't have any duplicate names for Projects, but when
accessing this method from a client, I got a message error at JBoss console
that means there is a problem because that query returns more than one register!
So, I changed the method signature and tested the following:
anonymous wrote :
| public Collection findByName(String name) throws RemoteException {
| Collection result = entityManager.createQuery("from Project p
where p.name = name").getResultList();
| return result;
| }
|
And then I got a Collection with all registers from table "PROJECT" !
I seems that problem is something about my EJB QL sintax. So I made another
change...
| public Project findByName(String name) throws RemoteException {
| return (Project)entityManager.createQuery("from Project p where
p.name = '" + name + "'").getSingleResult();
| }
|
And it works! Finally I got only one register from my query. But it does not
seems to be so ellegant syntax, and it's different from syntax used at JBoss
3.0 TrailBlazer.
So I ask you:
Why my first code returns all registers from table?
What is the best approach to find objects using EJB QL?
Is that possible to pass parameters using "?1", "?2", "?n" syntax? How?
Thank you all, for your attemption.
Fabricio Braga
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3917353#3917353
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3917353
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user