[jboss-user] [EJB 3.0] - Re: Illegalargumentexception on calling namedquery

jaikiran do-not-reply at jboss.com
Sat Jun 7 04:48:55 EDT 2008


"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



More information about the jboss-user mailing list