  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | - Re: Seam form submission errors | - Re: Seam form submission errors 2007-07-13 - By jbrosan
Back It seems that I have all of the data from the form and that its crashing on the em.persist(user) line. I'm not sure why though.
UserModifyActionImpl.java
| package org.bigbadwolf.core.component; | | import java.util.List ; | | import javax.ejb.Stateless; | import javax.persistence.EntityManager; | import javax.persistence.PersistenceContext; | | import org.jboss.seam.annotations.In; | import org.jboss.seam.faces.FacesMessages; | import org.jboss.seam.annotations.Name; | | import org.bigbadwolf.core.model.security.UserImpl; | | @(protected) | @(protected)("usermodifyaction") | public class UserModifyActionImpl implements UserModifyAction { | | @(protected)(create=true) | private UserImpl user; | | @(protected) | private EntityManager em; | | | public String addUser() | { | List existing = em.createQuery("select userName from UserImpl u where userName=:userName").setParameter("userName", user.getUserName()) .getResultList(); | | if (existing.size()==0) | { | | em.persist(this.user); | //log.info("Registered new user #{user.username}"); | return "/admin/user/userlist.xhtml"; | } | else | { | FacesMessages.instance().add("User #{user.userName} already exists"); | return null; | } | } | } | |
UserImpl.java
| package org.bigbadwolf.core.model.security; | | import java.util.ArrayList ; | import java.util.Date ; | import java.util.HashSet ; | import java.util.List ; | import java.util.Set ; | | import javax.annotation.security.RolesAllowed; | import javax.persistence.CascadeType; | import javax.persistence.Column; | import javax.persistence.Entity; | import javax.persistence.FetchType; | import javax.persistence.GeneratedValue; | import javax.persistence.GenerationType; | import javax.persistence.Id; | import javax.persistence.JoinColumn; | import javax.persistence.JoinTable; | import javax.persistence.ManyToMany; | import javax.persistence.OrderBy; | import javax.persistence.Table; | | import org.apache.commons.lang.RandomStringUtils ; | import org.bigbadwolf.core.Globals; | import org.hibernate.validator.Email; | import org.hibernate.validator.Length; | import org.hibernate.validator.NotNull; | import org.jboss.seam.ScopeType; | import org.jboss.seam.annotations.Name; | import org.jboss.seam.annotations.Scope; | | @(protected) | @(protected)(name = "Users") | @(protected)("user") | @(protected)(ScopeType.SESSION) | public class UserImpl implements User | { | | private static final long serialVersionUID = 5927788462600388688L; | | | @(protected)(fetch = FetchType.LAZY, cascade = { CascadeType.MERGE }) | @(protected)(name = "UsersToRoles", inverseJoinColumns = { @(protected) (name = "role_id", referencedColumnName = "id") }, joinColumns = { @(protected) (name = "user_id", referencedColumnName = "id") }) | @(protected)("name") | protected List<RoleImpl> roles; | | @(protected) | @(protected)(name = "id", columnDefinition = "bigint") | @(protected)(strategy=GenerationType.AUTO) | protected Integer id; | | @(protected)(name = "first_name") | protected String firstName; | | @(protected)(name = "last_name") | protected String lastName; | | @(protected)(name = "password") | protected String password; | | @(protected)(name = "email") | @(protected) | protected String email; | | @(protected)(name = "username") | protected String userName; | | @(protected)(name = "last_visit") | protected Date lastVisit; | | | public UserImpl() | { | } | public UserImpl(String firstName, String lastName, String password, String email, String userName) | { | this.firstName = firstName; | this.lastName = lastName; | this.password = password; | this.email = email; | this.userName = userName; | } | | @(protected)("administrator") | public String getPassword() | { | return password; | } | | @(protected) | @(protected)(min=3, max=15) | public void setPassword(String password) | { | this.password = password; | } | | | public Set<String> getRoleNames() | { | Set<String> roleNames = new HashSet<String>(); | List<RoleImpl> roles = getRoles(); | for (RoleImpl role : roles) | { | roleNames.add(role.getName()); | } | return roleNames; | } | | public boolean addRoles(List<Role> roles) | { | if (addRoles(roles)) | { | return true; | } | return false; | } | public boolean removeRoles(List<Role> roles) | { | if (removeRoles(roles)) | { | return true; | } | return false; | } | | @(protected)("administrator") | public void setEmail(String email) | { | | if (!email.matches(Globals.EMAIL_PATTERN)) | { | //throw new ValidationException("Invalid email.", Severity .ERROR); | } | | this.email = email; | } | | @(protected)("administrator") | @(protected)(min=5, max=15) | public void setFirstName(String firstName) | { | this.firstName = firstName; | } | @(protected)("administrator") | @(protected)(min=3, max=20) | public void setLastName(String lastName) | { | this.lastName = lastName; | } | | @(protected)("administrator") | @(protected) | @(protected)(min=5, max=15) | public void setUserName(String userName) | { | this.userName = userName; | } | public boolean isInRole(String roleName) | { | // Map<String, Object> parameters = new HashMap<String, Object>(); | // parameters.put("id", getId()); | // parameters.put("roleName", roleName); | // String returnedRoleName = (String) getQueryService() .singleResultNamedQuery(new StringBuffer(PersonImpl.class.getName()) | // .append(".isInRole").toString(), parameters); | // if (returnedRoleName != null && returnedRoleName.equals(roleName)) | // { | // return true; | // } | return false; | } | // public static UserImpl createNew() | // { | // UserImpl user = new UserImpl(); | // user.setPassword(RandomStringUtils.randomAlphanumeric(6) .toLowerCase()); | // return user; | // } | public String getName() | { | return userName; | } | public List<RoleImpl> getRoles() | { | if (roles == null) | { | roles = new ArrayList<RoleImpl>(); | } | return roles; | } | | | public String getEmail() { | return email; | } | | public String getFirstName() { | return firstName; | } | | public String getLastName() { | return lastName; | } | | public String getUserName() { | return userName; | } | public void generateNewPassword(Integer size) | { | setPassword(RandomStringUtils.randomAlphanumeric(size).toLowerCase( )); | } | public Date getLastVisit() | { | return lastVisit; | } | public void setLastVisit(Date lastVisit) | { | this.lastVisit = lastVisit; | } | public String getCreationId() { | // TODO Auto-generated method stub | return null; | } | public Integer getId() { | // TODO Auto-generated method stub | return null; | } | | } |
Any suggestions on what is could be causing this and/or suggested fix would be most welcome.
Thanks, John
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic &p=4064164#4064164
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode =reply&p=4064164 __ ____ ____ ____ ____ ____ ____ ____ ____ ____ jboss-user mailing list jboss-user@(protected) https://lists.jboss.org/mailman/listinfo/jboss-user
|
|
 |