[EJB 3.0] - Re: Illegalargumentexception on calling namedquery
by jaikiran
"aukenoppe" wrote :
|
| but how about the namedqueries defined in the User entitybean?
| you have to call them using the createNamedQuery method from the entitymanager.
Sorry, i did not understand this question. Here's how i have a NamedQuery declared for my entity User and then using it in a bean to fetch all the users. I have this working on JBoss-4.2.2GA:
User.java:
| @Entity
| @Table (name="User")
| @NamedQuery(name = "User.getAllUsers", query = "SELECT u FROM User u")
| public class User implements Serializable {
|
| /**
| * Id
| */
| @Id
| @GeneratedValue
| @Column (name="id")
| private long id;
|
| /**
| * User name
| */
| @Column (name="name")
| private String name;
| ...........
| //other stuff
| }
|
UserManagerBean.java:
| @Stateless
| @Remote( { UserManager.class })
| @RemoteBinding(jndiBinding = "RemoteUserManagerBean")
| public class UserManagerBean implements UserManager {
|
|
| @PersistenceContext
| private EntityManager entityManager;
|
| public User getUsers() {
|
| System.out.println("Using named query");
| List namedQueryResult = entityManager.createNamedQuery("User.getAllUsers").getResultList();
| System.out.println("Number of users in system = " + namedQueryResult.size());
| }
| .........
| //other stuff
| }
|
And here's the output:
| 14:13:05,605 INFO [STDOUT] Using named query
| 14:13:05,683 INFO [STDOUT] Number of users in system = 1
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4156454#4156454
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4156454
17 years, 10 months
Delivery Status Notification (Failure)
by postmaster@lists.jboss.org
This is an automatically generated Delivery Status Notification.
Unable to deliver message to the following recipients, because the message was forwarded more than the maximum allowed times. This could indicate a mail loop.
280(a)technodom.kz
17 years, 10 months
Delivery Status Notification (Failure)
by postmaster@lists.jboss.org
This is an automatically generated Delivery Status Notification.
Unable to deliver message to the following recipients, because the message was forwarded more than the maximum allowed times. This could indicate a mail loop.
ya_k(a)technodom.kz
17 years, 10 months