紧急求助:ejb调用ejb 层之间传递对象 对象属性丢失问题(javaee7)
如题:
用ejb封装dao层
再用ejb封装service层
两个ejb在不同的jvm下
在dao层测试数据全部正常
但是在service层调dao层进行业务操作的时候
属性丢失
user对象还在
但是user对象内的属性id变成0 name为null 全部成默认初始化的值了
跪求助攻!!!
实体类代码如下:
@Entity
@Table(name="t_user")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(name="name")
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (int) id;
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof User)) {
return false;
}
User other = (User) object;
if (this.id != other.id) {
return false;
}
return true;
}
@Override
public String toString() {
return "demo.model.User[ id=" + id + " ]";
}
}
@Stateless(name="userDao",mappedName="userDao")
@Remote(UserDao.class)
@TransactionManagement(TransactionManagementType.CONTAINER)
public class UserDaoImpl implements UserDao{
@PersistenceContext(name="ThirdDemoPU")
private EntityManager manager;
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Override
public void save(User user) {
this.manager.persist(user);
System.out.println(user.getName());
}
@Override
public void delete(int id) {
this.manager.remove(this.manager.find(User.class, id));
}
@Override
public void update(User user) {
this.manager.merge(user);
}
@Override
public User get(int id) {
User user = this.manager.find(User.class, id);
System.out.print(user.getId()+":"+user.getName());
return user;
}
@Override
public List<User> query() {
String jpql = "select u from User u";
return this.manager.createQuery(jpql).getResultList();
}
@Override
public String sayHello(String name) {
return "hello,"+name;
}
}
@Stateless(mappedName="userService",name="userService")
@Remote(UserService.class)
@TransactionManagement(TransactionManagementType.CONTAINER)
public class UserServiceImpl implements UserService{
UserDao userDao = DaoUtil.getUserDao();
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void add(User user) {
System.out.println("添加的数据名:"+user.getName());
userDao.save(user);
}
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void del(int id) {
userDao.delete(id);
}
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void modify(User user) {
userDao.update(user);
}
@Override
public User findById(int id) {
System.out.print(userDao);
User user = userDao.get(id);
System.out.println(user.getName());
if(user == null){
System.out.println("查询结果为null");
return null;
}else{
System.out.print(user);
return user;
}
}
@Override
public List<User> search() {
List<User> users = userDao.query();
if(users == null || users.size()==0){
System.out.print("没有查询结果或者为null");
return null;
}else{
return users;
}
}
}