[JBoss-user] [EJB 3.0] - A exception with : org.hibernate.MappingException: Named que
A exception with : org.hibernate.MappingException: Named query not known. When my Servlet invoke like this: try { | InitialContext ctx = new InitialContext(); | log.info("InitialContext ctx = new InitialContext();"); | userFacad | log.info("userFacade =e = (UserFacadeService) ctx.lookup("UserFacade/local"); (UserFacadeService) ctx.lookup(\"UserFacade/local\");"); | } catch (Exception e) { | e.printStackTrace(); | log.info(e); | } | userFacade.regUser(new User(userName, password)); Jboss Server throw exception like that: exception | | javax.ejb.EJBTransactionRolledbackException: javax.persistence.PersistenceException: org.hibernate.MappingException: Named query not known: findUserByName | org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:89) | org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130) | org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:196) | org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98) | org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76) | org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98) | org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:54) | org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98) | org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78) | org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98) | org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47) | org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98) | org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106) | org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98) | org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:181) | org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:79) | $Proxy86.findByName(Unknown Source) | richie.gt.ejb3.facade.UserFacade.regUser(UserFacade.java:37) I don't know why it happened.Help~~This is UserFacade Class. public User regUser(User user) { | /** | * save a new User | */ | if (um.findByName(user.getUserName()) != null) | return null; | um.save(user); | return um.findByName(user.getUserName()); | //um is a instance of UserManager class | } This is UserManager Class: @NamedQueries( { | @NamedQuery(name = "findUserByName", query = "SELECT u FROM User u WHERE u.userName = : userName")}) | @Stateless | @Local( { richie.gt.ejb3.service.UserManagerService.class }) | public class UserManager implements UserManagerService { | | @PersistenceContext | protected EntityManager em; | | /** | * findByName (Func) | */ | public User findByName(String userName) { | return (User) em.createNamedQuery("findUserByName").setParameter( | "userName", userName).getSingleResult(); | | } | This is persistence.xml | | | java:MySqlDS | richie.gt.ejb3.manager.UserManager | | | true | thread | 1 | | | | Thank you~ your attention View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3942832#3942832 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3942832 --- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 ___ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user
[JBoss-user] [EJB 3.0] - Re: Without rhyme or reason? a ClassCastException occured!
I changed the servlet : | private void showUser(HttpServletRequest request, | HttpServletResponse response) { | try { | InitialContext ctx = new InitialContext(); | userSession = (userSession) ctx.lookup("userSessionBean/local"); | } catch (Exception e) { | e.printStackTrace(); | } | | Collection auser = userSession.getUsers(); | System.out.println(auser); | | if (auser != null) | for (User user : auser) { | System.out.println("User name : " + user.getName()); | System.out.println("User id : " + user.getId()); | System.out.println("User mgs : " + user.getMessage()); | } | } | Error msg: | 07:09:51,546 INFO [STDOUT] [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED] | 07:09:51,546 ERROR [[ejb_servlet]] Servlet.service() for servlet ejb_servlet threw exception | java.lang.ClassCastException: ejb.persistence.User | at servlet.ejb_servlet.showUser(ejb_servlet.java:53) | at servlet.ejb_servlet.doGet(ejb_servlet.java:89) | at javax.servlet.http.HttpServlet.service(HttpServlet.java:697) | View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3933887#3933887 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3933887 --- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 ___ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user
[JBoss-user] [EJB 3.0] - Re: Without rhyme or reason? a ClassCastException occured!
"richie-lea" wrote : There is a java.lang.ClassCastException: ejb.persistence.User. | | My servlet code is: | private void showUser(HttpServletRequest request, | | HttpServletResponse response) { | | try { | | InitialContext ctx = new InitialContext(); | | userSession = (userSession) ctx.lookup("userSessionBean/local"); | | } catch (Exception e) { | | e.printStackTrace(); | | } | | | | Collection auser = userSession.getUsers(); | | if (auser != null) | | for (User user : auser) { | | System.out.println("User name : " + user.getName()); | | System.out.println("User id : " + user.getId()); | | System.out.println("User mgs : " + user.getMessage()); | | } | | } | userSessionBean/local getUsers method code is: | | | public Collection getUsers() { | | // TODO Auto-generated method stub | | return em.createQuery("from User u").getResultList(); | | } | | My ejb.persistence.User class is: | | | package ejb.persistence; | | | | import javax.persistence.*; | | | | @Entity | | @Table(name = "user") | | public class User { | | private String name; | | | | private int id; | | | | private String message; | | | | public User() { } | | | | public User(String name, String message) { | | this.name = name; | | this.message = message; | | } | | | | @Id | | @GeneratedValue | | public int getId() { | | return id; | | } | | | | public void setId(int id) { | | this.id = id; | | } | | | | public String getMessage() { | | return message; | | } | | | | public void setMessage(String message) { | | this.message = message; | | } | | | | public String getName() { | | return name; | | } | | | | public void setName(String name) { | | this.name = name; | | } | | } | | Log msg: | | | 06:43:44,937 ERROR [[ejb_servlet]] Servlet.service() for servlet ejb_servlet threw exception | | java.lang.ClassCastException: ejb.persistence.User | | at servlet.ejb_servlet.showUser(ejb_servlet.java:51) | | at servlet.ejb_servlet.doGet(ejb_servlet.java:87) | | at javax.servlet.http.HttpServlet.service(HttpServlet.java:697) | | . | | | Sorry for the long post, hope you're still with me. My questions is: | Why did the ClassCastException occured? What's wrong? View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3933885#3933885 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3933885 --- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 ___ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user
[JBoss-user] [EJB 3.0] - Without rhyme or reason? a ClassCastException occured!
There is a java.lang.ClassCastException: ejb.persistence.User. My servlet code is: private void showUser(HttpServletRequest request, | HttpServletResponse response) { | try { | InitialContext ctx = new InitialContext(); | userSession = (userSession) ctx.lookup("userSessionBean/local"); | } catch (Exception e) { | e.printStackTrace(); | } | | Collection auser = userSession.getUsers(); | if (auser != null) | for (User user : auser) { | System.out.println("User name : " + user.getName()); | System.out.println("User id : " + user.getId()); | System.out.println("User mgs : " + user.getMessage()); | } | } userSessionBean/local getUsers method code is: | public Collection getUsers() { | // TODO Auto-generated method stub | return em.createQuery("from User u").getResultList(); | } My ejb.persistence.User class is: | package ejb.persistence; | | import javax.persistence.*; | | @Entity | @Table(name = "user") | public class User { | private String name; | | private int id; | | private String message; | | public User() { } | | public User(String name, String message) { | this.name = name; | this.message = message; | } | | @Id | @GeneratedValue | public int getId() { | return id; | } | | public void setId(int id) { | this.id = id; | } | | public String getMessage() { | return message; | } | | public void setMessage(String message) { | this.message = message; | } | | public String getName() { | return name; | } | | public void setName(String name) { | this.name = name; | } | } Sorry for the long post, hope you're still with me. My questions is: Why is there a ClassCastException occured? What's wrong? View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3933884#3933884 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3933884 --- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 ___ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user
[JBoss-user] [EJB 3.0] - Re: where is my data?
Thx , I got it. View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3932759#3932759 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3932759 --- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 ___ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user
[JBoss-user] [EJB 3.0] - Re: How to persist forever?
THX,I got it! View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3932758#3932758 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3932758 --- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 ___ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user
[JBoss-user] [EJB 3.0] - How to persist forever?
EJB 3.0 TrailBlazer: ---Configure Persistence Context "In addition, JBoss AS should create database tables for those entity beans when the application is deployed, and delete those tables when the application is un-deployed. Note that the application is deployed and un-deployed automatically at the server startup or shutdown." It means that if I shutdown or restart the JBoss AS,all the data I stored will be lost? illustration: When the AS was terminated,how to make my app's data come back after the AS restart well. View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3932722#3932722 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3932722 --- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 ___ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user
[JBoss-user] [EJB 3.0] - Re: where is my data?
It's a EntityBean lifecycle problem?? View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3932718#3932718 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3932718 --- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 ___ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user
[JBoss-user] [EJB 3.0] - where is my data?
There is a Puzzled question. I written a class User like this: @Entity @Table(name = "user") public class User { private String name; private int id; private String message; public User() { } public User(String name, String message) { this.name = name; this.message = message; } @Id @GeneratedValue public int getId() { return id; } public void setId(int id) { this.id = id; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public String getName() { return name; } public void setName(String name) { this.name = name; } } and I written a Manager class like this: @PersistenceContext EntityManager em; .. User user = new User(name, message); em.persist(user); . When the JBoss Server is running,everything is OK. the application create a new table named "user",and add data into the table.But after I close Server, I found everything is lost."user" table cannot de find,and data is yet!!! what happend? View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3932664#3932664 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3932664 --- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 ___ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user