[EJB 3.0 Users] - Simple hibernate web app
by pepelara
Hello,
I am a newbe in Hibernate but I am learning quickly. But I have reached a point that is taking me a lot of time.
I have developed a pretty simple web. It is just two JSP, index.jsp that redirects to user.jsp where I have all the code.
This is user.jsp,
| <%@page import="com.examscam.dao.*,com.examscam.model.*,
| com.examscam.util.*,org.hibernate.*;" contentType="text/html;" %>
|
| <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
| <jsp:useBean class="com.examscam.model.User" id="user" scope="request"/>
| <jsp:setProperty name="user" property="*" />
|
| <%
| HibernateUtil.beginTransaction();
| UserDAO userDAO = new HibernateUserDAO();
| java.util.List<User> users = null;
| String command = request.getParameter("command");
| if (command != null) {
| if (command.equals("Create")) {
| userDAO.create(user);
| }
| if (command.equals("Update")) {
| userDAO.update(user);
| }
| if (command.equals("edit")) {
| user = userDAO.findByPrimaryKey(user.getId());
| request.setAttribute("user", user);
| }
| if (command.equals("delete")) {
| userDAO.delete(user);
| request.setAttribute("user", null);
| }
| if (command.equals("Fuzzy Search")) {
| users = userDAO.findByExample(user, true);
| }
| if (command.equals("Strict Search")) {
| users = userDAO.findByExample(user, false);
| }
| if (command.equals("Clear")) {
| request.setAttribute("user", null);
| }
| }
| if (users == null) {
| users = userDAO.findAll();
| }
| request.setAttribute("users", users);
| HibernateUtil.commitTransaction();
| %>
|
| <html>
| <body>
| <form action="user.jsp">
| <!-- Here are our four textfields -->
| <input type="text" size="7"
| name="id" value=""> Id
| <BR/>
| <input type="text" size="30"
| name="loginName" value=""> Name
| <BR/>
| <input type="text" size="30"
| name="password" value=""> Password
| <BR/>
| <input type="text" size="30"
| name="emailAddress" value=""> Email
| <BR/>
| <!-- Here are all of our buttons!!! -->
| <input type="submit" name="command" value="Strict Search">
| <input type="submit" name="command" value="Fuzzy Search">
| <input type="submit" name="command" value="Update">
| <input type="submit" name="command" value="Create">
| <input type="submit" name="command" value="Clear">
| <BR>
| <c:forEach items="" var="user">
| <c:url var="editurl" value="user.jsp" >
| <c:param name="command" value="edit" />
| <c:param name="id" value=""/>
| </c:url>
| <c:url var="deleteurl" value="user.jsp" >
| <c:param name="command" value="delete" />
| <c:param name="id" value=""/>
| </c:url>
| <a href="">edit</a>
| <a href="">delete</a>
| <c:out value="" />
| <c:out value="" />
| <c:out value="" />
| <BR/>
| </c:forEach>
| </form>
| </body>
| </html>
|
The problem is that I am not building the web app correctly. For user.jsp I import a jar, hibernatedaoaccess.jar, where are the classes and interfaces I need,
| package com.examscam.dao;
|
| import java.util.List;
| import com.examscam.model.User;
|
| public interface UserDAO {
|
| public User create(User user);
| public boolean update(User user) ;
| public boolean delete(User user) ;
| public User findByPrimaryKey(Long primaryKey);
| public List<User> findByExample(User user, boolean fuzzy);
| public List<User> findAll();
|
| }
|
| package com.examscam.model;
|
| import javax.persistence.Entity;
| import javax.persistence.GeneratedValue;
| import javax.persistence.Id;
| import javax.persistence.Column;
| import javax.persistence.Table;
| import javax.persistence.Basic;
| import javax.persistence.Temporal;
| import javax.persistence.TemporalType;
| import javax.persistence.Transient;
|
| @Entity
| @Table (name="user", schema="examscam")
| public class User {
| private Long id;
| private String loginName;
| private String password;
| private String encryptedPassword;
| private String emailAddress;
| private Boolean verified;
| private java.util.Date lastAccessTime;
| private java.util.Calendar registrationDate;
|
| @Transient
| public String getEncryptedPassword() {
| return encryptedPassword;
| }
| public void setEncryptedPassword(String ep) {
| this.encryptedPassword = ep;
| }
|
| @Id
| @GeneratedValue
| @Column (name="id")
| public Long getId() {
| return id;
| }
| public void setId(Long id) {
| this.id = id;
| }
|
| @Column (name="login_name")
| public String getLoginName() {
| return loginName;
| }
| public void setLoginName(String loginName) {
| this.loginName = loginName;
| }
|
| @Column (name="password", nullable=false)
| public String getPassword() {
| return password;
| }
| public void setPassword(String password) {
| this.password = password;
| }
|
| @Column (name="emailAddress")
| public String getEmailAddress() {
| return emailAddress;
| }
|
| @Temporal(TemporalType.TIMESTAMP)
| public java.util.Date getLastAccessTime() {
| return lastAccessTime;
| }
|
| @Temporal(TemporalType.DATE)
| public java.util.Calendar getRegistrationDate() {
| return registrationDate;
| }
|
| @Basic
| public Boolean isVerified() {
| return verified;
| }
|
| public void setEmailAddress(String emailAddress) {
| this.emailAddress = emailAddress;
| }
|
| public void setLastAccessTime
| (java.util.Date lastAccessTime) {
| this.lastAccessTime = lastAccessTime;
| }
|
| public void setRegistrationDate
| (java.util.Calendar registrationDate){
| this.registrationDate = registrationDate;
| }
|
| public void setVerified(Boolean verified) {
| this.verified = verified;
| }
|
| public String toString() {
| return getId() + " : " +
| getLoginName() + " : " +
| getPassword() + " : " +
| getEmailAddress();
| }
| }
|
| package com.examscam.dao;
|
| import java.util.List;
| import org.hibernate.Criteria;
| import org.hibernate.Query;
| import org.hibernate.Session;
| import org.hibernate.criterion.Example;
| import org.hibernate.criterion.MatchMode;
| import com.examscam.model.User;
|
|
| public class HibernateUserDAO extends ExamScamDAO implements UserDAO {
|
| public User create(User user) {
| // TODO Auto-generated method stub
| if (user.getId() != null && user.getId() != 0) {
| user = null;
| }
| else {
| user.setLastAccessTime(new java.util.Date());
| user.setRegistrationDate
| (new java.util.GregorianCalendar());
| user.setVerified(false);
| super.save(user);
| }
| return user;
| }
|
| public boolean update(User user) {
| // TODO Auto-generated method stub
| boolean successFlag = true;
|
| try {
| if (user.getId() == null || user.getId() == 0) {
| successFlag = false;
| }else {
| super.save(user);
| }
| }
| catch (Throwable th) {
| successFlag = false;
| }
|
| return successFlag;
| }
|
| public boolean delete(User user) {
| // TODO Auto-generated method stub
| boolean successFlag = true;
|
| try {
| user.setPassword(" ");
| super.delete(user);
| } catch (Throwable th) {
| successFlag = false;
| }
|
| return successFlag;
| }
|
| @SuppressWarnings("unchecked")
| public List<User> findAll() {
| // TODO Auto-generated method stub
| String queryString = "from User";
| List<User> allUsers;
| Query queryResult =
| this.getSession().createQuery(queryString);
| allUsers = (List<User>) queryResult.list();
|
| return allUsers;
|
| }
|
| @SuppressWarnings("unchecked")
| public List<User> findByExample(User user, boolean fuzzy) {
| // TODO Auto-generated method stub
| List<User> users = null;
| Session session = this.getSession();
| Criteria criteria =
| session.createCriteria(User.class);
| Example example = Example.create(user);
| if (fuzzy) {
| example.enableLike(MatchMode.ANYWHERE);
| example.ignoreCase();
| example.excludeZeroes();
| }
| criteria.add(example);
| List<User> list = (List<User>) criteria.list();
| users = list;
| return users;
|
| }
|
| public User findByPrimaryKey(Long primaryKey) {
| // TODO Auto-generated method stub
| User user = (User)
| super.findByPrimaryKey(User.class, primaryKey);
|
| return user;
|
| }
|
| }
|
The question is depending on where I put the jar, running the web app against JBoss 4.2.2 GA, it does not find the hibernate.cfg.xml file or the interface UserDao as well.
And I can not get it works.
Any idea?
I am developing on Eclipse Ganymede RS1 that integrates the Data Base if needed and the apps server.
Thanking in advance,
Jose
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4262842#4262842
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4262842
16 years, 5 months
[JBoss Messaging Users] - Load balancing with new node
by yongz
Hi,
* JBoss 5.01
* JBoss Messaging 1.4.2.GA-SP1
I have a question about JBM Client-Side Load balancing:
With Round Robin policy, the connections are spread smoothly across 3 nodes in the cluster, say: A,B,C.
While the job is running with the connections to A,B,C, and now there is another new node, say D, joins the cluster.
If a new connection is required to be created to D, is there any way that we can *ensure* this new connection will be created on D? and not to A,B,or C?
Thanks in advance.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4262839#4262839
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4262839
16 years, 5 months
[EJB 3.0 Users] - Re: NotBoundException when @Service POJO invoke EJB
by steeven
Wolfgang, I have tried many names found in JNDI, none of them worked. Would you please post your Depends name? maybe I have to make EJB also as a @service?
| @Service(name = CmModule.SERVICE_NAME)
| @Depends( { "/MoService", "/ems/MoService", "/IMoService", "/ems/MoService/remote",
| "/ems/MoService/remote-com.genband.ems.gvu.server.mo.IMoService", "MoService", "ems/MoService", "IMoService",
| "ems/MoService/remote", "ems/MoService/remote-com.genband.ems.gvu.server.mo.IMoService" })
| public class CmModule implements ICmModule {
| public final static String SERVICE_NAME = "CmModule";
| // @PersistenceContext
| // private EntityManager em;
|
| Logger log = LoggerFactory.getLogger(CmModule.class);
|
| @EJB
| private IMoService moService;
| ....
| }
|
Error message:
DEPLOYMENTS IN ERROR:
| Deployment "<UNKNOWN jboss.j2ee:ear=ems.ear,jar=ems-server.jar,name=CmModule,service=EJB3>" is in error due to the following reason(s): ** UNRESOLVED Demands 'ems/MoService/remote' **, ** UNRESOLVED Demands '/MoService' **, ** UNRESOLVED Demands '/IMoService' **, ** UNRESOLVED Demands '/ems/MoService/remote-com.genband.ems.gvu.server.mo.IMoService' **, ** UNRESOLVED Demands '/ems/MoService/remote' **, ** UNRESOLVED Demands 'IMoService' **, ** UNRESOLVED Demands 'ems/MoService/remote-com.genband.ems.gvu.server.mo.IMoService' **, ** UNRESOLVED Demands '/ems/MoService' **, ** UNRESOLVED Demands 'ems/MoService' **, ** UNRESOLVED Demands 'MoService' **
|
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4262834#4262834
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4262834
16 years, 5 months
[EJB 3.0 Users] - Is there actual useful books/documentation on EntityQuery?
by nmatrix9
Hello EJB 3.0 Users,
I'm stuck on trying implement/use certain EJB 3.0 EntityQuery methods. A fellow EJB 3.0 user suggested I go to http://docs.jboss.org/seam/2.0.0.GA/api/. I mean it's great that theres a actual "reference" to the methods of EntityQuery but as far providing useful context and details on using the methods they might as well have shown me a blank page. Are there books, DETAILED documentations or tutorials on using the EntityQuery methods? Instead of just for example:
"protected void setRestrictionParameterValues(List restrictionParameterValues)"
and leaving that as the ultimate answer to life, the universe and everything in it? A picture is worth a thousand words. A good example . . . about three thousand.
One thing I don't understand about the java online documentation in general is why can't people post comments about the the methods or how it's implemented in general to provide guidance to new users about a particular technology? PHP does it, which is probally one reason why it has such a high adoption. But for some reason any sort of Java Documentation online which is quite sparse tries to be as mysterious and arcane as possible. This is just my personal observation.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4262826#4262826
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4262826
16 years, 5 months
[jBPM Users] - [jBPM 4.1] Signavio editor : default install failed
by Thierry33
Hi !
I wanted to install the signavio editor. I used the default ant task described in the user manual.
It fails...
My JDK is 1.6
Any idea why ?
java.lang.RuntimeException: org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):
*** DEPLOYMENTS IN ERROR: Name -> Error
vfsfile:/D:/jbpm-4.1/jboss-5.0.0.GA/server/default/deploy/jbpmeditor.war/ -> org.jboss.deployers.spi.DeploymentException: Error during deploy: vfsfile:/D:/jbpm-4.1/jboss-5.0.0.GA/server/default/deploy/jbpmeditor.war/
DEPLOYMENTS IN ERROR:
Deployment "vfsfile:/D:/jbpm-4.1/jboss-5.0.0.GA/server/default/deploy/jbpmeditor.war/" is in error due to the following reason(s): java.lang.IllegalArgumentException: The context vfsfile:/D:/jbpm-4.1/jboss-5.0.0.GA/server/default/deploy/jbpmeditor.war/ is already registered in domain jbpmeditordomain
at org.jboss.profileservice.management.upload.remoting.StreamingDeploymentTarget.invoke(StreamingDeploymentTarget.java:313)
at org.jboss.profileservice.management.upload.remoting.StreamingDeploymentTarget.start(StreamingDeploymentTarget.java:190)
at org.jboss.profileservice.management.upload.DeploymentProgressImpl.start(DeploymentProgressImpl.java:231)
at org.jboss.profileservice.management.upload.DeploymentProgressImpl.run(DeploymentProgressImpl.java:88)
at org.rhq.plugins.jbossas5.util.DeploymentUtils.run(DeploymentUtils.java:120)
at org.rhq.plugins.jbossas5.AbstractManagedDeploymentComponent.invokeOperation(AbstractManagedDeploymentComponent.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.rhq.core.pc.inventory.ResourceContainer$ComponentInvocationThread.call(ResourceContainer.java:482)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):
*** DEPLOYMENTS IN ERROR: Name -> Error
vfsfile:/D:/jbpm-4.1/jboss-5.0.0.GA/server/default/deploy/jbpmeditor.war/ -> org.jboss.deployers.spi.DeploymentException: Error during deploy: vfsfile:/D:/jbpm-4.1/jboss-5.0.0.GA/server/default/deploy/jbpmeditor.war/
DEPLOYMENTS IN ERROR:
Deployment "vfsfile:/D:/jbpm-4.1/jboss-5.0.0.GA/server/default/deploy/jbpmeditor.war/" is in error due to the following reason(s): java.lang.IllegalArgumentException: The context vfsfile:/D:/jbpm-4.1/jboss-5.0.0.GA/server/default/deploy/jbpmeditor.war/ is already registered in domain jbpmeditordomain
at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:993)
at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:939)
at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:873)
at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.checkComplete(MainDeployerAdapter.java:128)
at org.jboss.profileservice.management.upload.remoting.AbstractDeployHandler.start(AbstractDeployHandler.java:265)
at org.jboss.profileservice.management.upload.remoting.AbstractDeployHandler.invoke(AbstractDeployHandler.java:177)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:891)
at org.jboss.remoting.transport.local.LocalClientInvoker.invoke(LocalClientInvoker.java:106)
at org.jboss.remoting.Client.invoke(Client.java:1724)
at org.jboss.remoting.Client.invoke(Client.java:629)
at org.jboss.profileservice.management.upload.remoting.StreamingDeploymentTarget.invoke(StreamingDeploymentTarget.java:305)
... 15 more
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4262819#4262819
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4262819
16 years, 5 months