Попробуйте это. С датой и календарем
public class StockCodeGenerator
implements IdentifierGenerator
{
private static Logger log = Logger.getLogger(StockCodeGenerator.class);
public StockCodeGenerator() {}
public int generateCustId()
{
Random random = new Random();
return random.nextInt(100);
}
public Serializable generate(SessionImplementor session, Object object)
throws HibernateException
{
String prefix = "Custom_String";
Connection connection = session.connection();
System.out.println(session.connection());
Date date = new Date();
Calendar calendar = Calendar.getInstance();
return prefix + "_" + generateCustId() + "_" + calendar.get(1);
}
}
А затем используйте его в аннотации @GenericGenerator
@Id
@GenericGenerator(name="seq_id",strategy="com.mvc.StockCodeGenerator.
StockCodeGenerator")
@GeneratedValue(generator="seq_id")