使用带有后缀的自定义 id 生成器时出现休眠错误



我正在尝试为我的实体创建自定义ID,但是当我尝试这样做时,我遇到了错误。

这是我的实体(部分(代码

@Entity
@Table(name = "notifications")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Notifications implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE , generator = "seq_notifications")
@GenericGenerator(name = "seq_notifications",
strategy = "com.mycompany.myapp.domain.PKeys.NotficationID")
private String id;

这是生成器类代码


public class NotficationID  extends SequenceStyleGenerator {
public static final String DATE_FORMAT_PARAMETER = "dateFormat";
public static final String DATE_FORMAT_DEFAULT = "%tY-%tm";
public static final String NUMBER_FORMAT_PARAMETER = "numberFormat";
public static final String NUMBER_FORMAT_DEFAULT = "%05d";
public static final String DATE_NUMBER_SEPARATOR_PARAMETER = "dateNumberSeparator";
public static final String DATE_NUMBER_SEPARATOR_DEFAULT = "_";
private String format;
@Override
public Serializable generate(SharedSessionContractImplementor session,
Object object) throws HibernateException {
return String.format(format, LocalDate.now(), super.generate(session, object));
}
@Override
public void configure(Type type, Properties params,
ServiceRegistry serviceRegistry) throws MappingException {
super.configure(LongType.INSTANCE, params, serviceRegistry);
String dateFormat = ConfigurationHelper.getString(DATE_FORMAT_PARAMETER, params, DATE_FORMAT_DEFAULT).replace("%", "%1");
String numberFormat = ConfigurationHelper.getString(NUMBER_FORMAT_PARAMETER, params, NUMBER_FORMAT_DEFAULT).replace("%", "%2");
String dateNumberSeparator = ConfigurationHelper.getString(DATE_NUMBER_SEPARATOR_PARAMETER, params, DATE_NUMBER_SEPARATOR_DEFAULT);
this.format = dateFormat+dateNumberSeparator+numberFormat;
}
}

当我尝试插入值时出现此错误

2020-06-25 09:56:14.718 DEBUG 15572 --- [  XNIO-1 task-4] c.m.m.web.rest.NotificationsResource     : REST request to save Notifications : Notifications{id=null, notificationType='null', notificationDate='null', message='null'}
Hibernate: select next_val as id_val from seq_notifications for update
2020-06-25 09:56:14.744 ERROR 15572 --- [  XNIO-1 task-4] o.hibernate.id.enhanced.TableStructure   : could not read a hi value
java.sql.SQLSyntaxErrorException: Table 'relationships.seq_notifications' doesn't exist

2020-06-25 09:56:14.746  WARN 15572 --- [  XNIO-1 task-4] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 1146, SQLState: 42S02
2020-06-25 09:56:14.746 ERROR 15572 --- [  XNIO-1 task-4] o.h.engine.jdbc.spi.SqlExceptionHelper   : Table 'relationships.seq_notifications' doesn't exist
2020-06-25 09:56:14.753 ERROR 15572 --- [  XNIO-1 task-4] c.m.m.web.rest.NotificationsResource     : Exception in createNotifications() with cause = 'org.hibernate.exception.SQLGrammarException: error performing isolated work' and exception = 'error performing isolated work; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: error performing isolated work'

请注意,我正在使用jhipster

提前谢谢。

我想问题是桌子,我创建了一个表格,一切都很好,谢谢@Henrique,你是对的,

我创建了一个名为"seq"的表,但数据类型是 varchar(255(,因为我的@Id是一个字符串

最新更新