0
私はdirectDebitクラスのidのシーケンスを作成したかったのです。 その日には、その日に作成された番号を示す数字(dd_mm_yy)の形式で日付を入力します。MySQLでシーケンス番号を数字で作成する
// Class in java
@Entity
public class DirectDebit implements Serializable {
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "directDebit_generator")initialValue=1, allocationSize=50)
@Id
private String id;
...
}
-- create sequence in mysql
CREATE SEQUENCE directDebit_generator
START WITH 1
MAXVALUE 99999999
MINVALUE 1
NOCYCLE
NOCACHE
NOORDER;
-- Format date in mysql
SELECT DATE_FORMAT(CURRENT_TIMESTAMP, '%d_%m_%Y');
//Examples of id today
10_12_2016_1
10_12_2016_2
10_12_2016_3
...
//Examples of id yesterday
09_12_2016_1
09_12_2016_2
...
私は何をしたいですか?
しかし、どのように私は発電機のコードを作るのですか? –
つまり、Display Date.format(LocalDateTime.now()、 "dd_MM_YY")を配置します。 そして番号を増やす方法。 –
カスタム発電機を書くのは非常に難しいです。ここに2つのexmaples https://vladmihalcea.com/2016/06/13/how-to-implement-a-custom-string-based-sequence-identifier-generator-with-hibernate/ http://blog.anorakgirlがあります。 co.uk/2009/01/custom-hibernate-sequence-generator-for-id-field/ – jklee