I need help for persisting into oracle database

61 Views Asked by At

There is a problem about generating id while persisting into database. I added the following code to my jpa entity file, however I'm getting 0 for personid.

@Id
@Column(unique=true, nullable=false, precision=10, name="PERSONID")
@SequenceGenerator(name="appUsersSeq", sequenceName="SEQ_PERSON", allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "appUsersSeq")
private long personid;

EjbService:

@Stateless
public class EjbService implements EjbServiceRemote {

@PersistenceContext(name = "Project1245")
private EntityManager em;


@Override
public void addTperson(Tperson tp) {
    em.persist(tp);

}

}
1

There are 1 best solutions below

9
Guillermo On

0 is default value for long type. The id will be set after invoking select query for the related sequence, which commonly is executed when you persist the entity. Are you persisting the entity? In case yes, post the database sequence definition to check it.