hi, i have some problem with my project, can u help me??? I google but no solution found...:(
I used hibernate, strust 2 and spring to manage transaction.
I want to try catch username in New.java, username is a PK, this pape throw can throw excetption error but the server still appear error.
New.java
package actions.users;
import data.User;
import actions.base.BaseAction;
public class New extends BaseAction {
public String execute() {
if (userName != null && userName.length() > 0) {
User u = new User();
u.setFirstName(firstName);
u.setLastName(lastName);
u.setUserName(userName);
u.setPassword(password);
u.setEmail(email);
u.setStreet(street);
u.setZipcode(zipcode);
u.setCity(city);
u.setRole(role);
try {
services.createUser(u);
return redirect("Listing.action");
} catch (Exception e) {
addActionError("Wrong!!!");
}
}
return "success";
}
String firstName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String value) {
this.firstName = value;
}
String lastName;
public String getLastName() {
return lastName;
}
public void setLastName(String value) {
this.lastName = value;
}
String userName;
public String getUserName() {
return userName;
}
public void setUserName(String value) {
this.userName = value;
}
String password;
public String getPassword() {
return password;
}
public void setPassword(String value) {
this.password = value;
}
String email;
public String getEmail() {
return email;
}
public void setEmail(String value) {
this.email = value;
}
String street;
public String getStreet() {
return street;
}
public void setStreet(String value) {
this.street = value;
}
String zipcode;
public String getZipcode() {
return zipcode;
}
public void setZipcode(String value) {
this.zipcode = value;
}
String city;
public String getCity() {
return city;
}
public void setCity(String value) {
this.city = value;
}
String role;
public String getRole() {
return role;
}
public void setRole(String value) {
this.role = value;
}
}
Services.java
package services;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional;
import data.*;
@Transactional
public class Services {
SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory value) {sessionFactory = value;}
public Session sess(){return sessionFactory.getCurrentSession();};
...
public void createItem(Item item) {sess().save(item);}
public void createUser(User user){sess().save(user);}
public void addBid(Bid bid) {sess().saveOrUpdate(bid);}
public void addBillingDetail(BillingDetail billingdetail) {sess().save(billingdetail);}
@SuppressWarnings("unchecked")
public List<Item> getItems() {return sess().createQuery("from Item").list();}
@SuppressWarnings("unchecked")
public List<User> getUsers(){return sess().createQuery("from User").list();}
@SuppressWarnings("unchecked")
public List<Bid> getBids() {return sess().createQuery("from Bid").list();}
}