사용자 도구

사이트 도구


database:mysql:sequence

문서의 이전 판입니다!


MySQL Sequence 시퀀스

Real MySQL 1판 922페이지

create table jpa_sequences ( name varchar(16) NOT NULL, curval bigint not null, primary key(name)) ENGINE=MyISAM;

insert into jpa_sequences set name='books', curval=(@v_current_value:=1) on duplicate key update curval=(@v_current_value:=curval+1);

select @v_current_value

      final EntityManager entityManager = getEntityManager();
      final Query generateNextSequenceQuery = entityManager.createNativeQuery("insert into jpa_sequences set name=?, curval=(@v_current_value\\:=1) on duplicate key update curval=(@v_current_value\\:=curval+1);");
      generateNextSequenceQuery.setParameter(1, sequenceName);
      generateNextSequenceQuery.executeUpdate();
      final Query nextSequenceQUery = entityManager.createNativeQuery("select @v_current_value;");
      Object nextSequenceObject = nextSequenceQUery.getSingleResult();
      if(nextSequenceObject instanceof BigInteger) {
          return ((BigInteger)nextSequenceObject).longValue();
      }
      return (Long)nextSequenceObject;
database/mysql/sequence.1405668668.txt.gz · 마지막으로 수정됨: 2014/07/18 16:31 저자 kwon37xi