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

解决方案 »

  1.   

    在ID上添加注解,@Id
    @GeneratedValue(strategy=GenerationType.AUTO)
      

  2.   

    AUTO不行,根据出错信息:Local Exception Stack: 
    Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'wuoodb.sequence' doesn't exist
    Error Code: 1146
    Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
            bind => [50, SEQ_GEN]
    Query: DataModifyQuery()应该是数据库需要一个自增序列,所以我设为IDENTITY之后就好了
      

  3.   

    http://topic.csdn.net/u/20090215/01/ced133c1-96fd-4636-9383-aef83ec3ebd7.html