posted 14 years ago
have the hibernate annotations set
@Entity
@Table( name="pens")
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="PEN_SEQ")
@SequenceGenerator(name="PEN_SEQ",sequenceName="PEN_ID_SEQ")
@Column( name="pen_id" , nullable = false, updatable=false )
private Integer id;
i have a pensidgenerator:
public class PenIdGenerator implements IdentifierGenerator {
public Serializable generate(SessionImplementor session, Object object)
throws HibernateException {
Connection connection = session.connection();
try {
PreparedStatement ps = connection.prepareStatement("SELECT MAX(pen_id) as nextval from pens");
ResultSet rs = ps.executeQuery();
if (rs.next()) {
int id = rs.getInt("nextval");
log.debug("Generated Pen ID: " + (id+1));
return id+1;
}
and i have SEquqnce cretaed in DB:
CREATE SEQUENCE PEN_ID_SEQ
MINVALUE 1
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO CYCLE
CACHE 24;
i am able to get the next val correctly when i try in the Database
but from the hibernate i am able to save a Pen but with some long Id ex: 18100.....
dont know what i am missing
thanks