SessionBean:
@Stateless
public class LoginBeanBean implements LoginBeanRemote, LoginBeanLocal {
@PersistenceContext(unitName = "wuooPU")
private EntityManager em;
public Login persist(Login login){
em.persist(login);
System.out.println("ejb insert loginid = "+login.getId());
return login;
}
}
EntityBean:
@Entity
@Table(name = "login")
public class Login implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id", nullable = false)
private Integer id;
@Column(name = "loginid", nullable = false)
private String loginid;
@Column(name = "password", nullable = false)
private String password;
下面一些get,set就不帖了
id是主键,database table中已设为自动增长列
最后jsp后台javabean中调用persist后,数据已插入数据库,但返回的id是null,请问怎样能得到自动增长的ID
------解决方案--------------------
在ID上添加注解,
@Id
@GeneratedValue(strategy=GenerationType.AUTO)