| |

VerySource

 Forgot password?
 Register
Search
View: 1824|Reply: 15

EJBQL condition query for help in EJB, LIST array

[Copy link]

2

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-3-23 10:30:01
| Show all posts |Read mode
I am using EJB to develop a web application. I created a user registry, mapped him as an entity, and made a simple query on the entity or by user.

There is no problem with searching by name. Now I want to combine with other systems, get a list of user names from other systems, and use the form LIST to list

Show listuser.
    I want to query in the registry all records where all usernames are contained in listuser. I want to use EJBSQL language to implement, but the experimental results are always unsuccessful

. Please help me analyze it.

   @PersistenceContext
    private EntityManager em;
 public List find (List listuserid)
{
       String connselect = "select OBJECT (o) from userinfo o where o.userID IN: userid";
            

Query query = em.createQuery (connselect);

               query.setParameter ("userid", listuserid);
   

          return query.getResultList ();
}




I found this usage in hibernate and setParameterlist method in hibernate, but I don't know why there isn't in EJB, as if I

Run to em.createQuery (connselect); and an error occurs.
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-18 09:30:01
| Show all posts
@PersistenceContext
private EntityManager em;
public List find(List listuserid){
Query query = em.createQuery("from userinfo o where o.userID IN(?1)");
query.setParameter(1, listuserid);
return query.getResultList();
}
Reply

Use magic Report

2

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-7-19 15:00:01
| Show all posts
Theleodutlupstairs, according to your method, can't get through, the same error.
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-19 17:00:01
| Show all posts
What is wrong?
Reply

Use magic Report

2

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-7-22 20:30:01
| Show all posts
After executing query.setParameter(1, listuserid); still catches an error, saying that it is a remote call error
Reply

Use magic Report

2

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-7-27 10:15:01
| Show all posts
Upstairsleodutl, I just tried it again, according to the method you said,
@PersistenceContext
private EntityManager em;
public List find(List listuserid){
Query query = em.createQuery("from userinfo o where o.userID IN(?1)");
query.setParameter(1, listuserid);
return query.getResultList();
}
When listuserid is a string type, there is no error, but when it is a LIST type, it is an error
Reply

Use magic Report

0

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-27 16:30:01
| Show all posts
Is there any relationship with the type of entity BEAN defined by the host? query.setParameter(1, listuserid); the attribute type of the corresponding bean should also be of type String, so there is no error when the passed listuserid is of type String.

PS: I guessed it. I just learned EJB for less than 2 weeks. I don’t want to say something wrong, don’t BS I, let’s study together.
Reply

Use magic Report

0

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-27 20:15:01
| Show all posts
@DataModel
private List<User> userList;//A view for display
@In(create=true)
@Out(required=false, scope=SESSION)
private User user;
...
public void findUsers() {
  Query query;
  query = em.createQuery("from User");
  query.setParameter("code", user.getUserCode());
  query.setParameter("userName",user.getUserName());
  userList = query.getResultList();
}


For reference, hehe, I wrote this easy to use, the other processing in the method body has been deleted, and the writing is the main one. ^^
Reply

Use magic Report

0

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-27 21:30:01
| Show all posts
Part of the code on the front page

<h:dataTable var="uls" value="#{userList}" rendered="#{userList.rowCount>0}"
styleClass="table" headerClass="tableHeader" columnClasses="right80, right80, right80, .left60">
<h:column>
           <f:facet name="header">
            <h:outputText value="ユーザコード"/>
           </f:facet>
           <s:link value="#{uls.userCode}" action="#{userManager.select}" escape="false"/>
        </h:column>
        <h:column>
           <f:facet name="header">
            <h:outputText value="ユーザ名"/>
           </f:facet>
           <s:link value="#{uls.userName}" action="#{userManager.select}" escape="false"/>
        </h:column>
     </h:dataTable>
Reply

Use magic Report

2

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-7-29 13:45:01
| Show all posts
Can the person upstairs give all of the following functions, why can't I pass it?

public void findUsers() {
  Query query;
  query = em.createQuery("from User");
  query.setParameter("code", user.getUserCode());
  query.setParameter("userName",user.getUserName());
  userList = query.getResultList();
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list