Моя конфигурация гибернации выглядит следующим образом:
@Bean
public JpaDialect hibernateJpaDialect() {
HibernateJpaDialect hibernateJpaDialect = new HibernateJpaDialect();
hibernateJpaDialect.setPrepareConnection(true);
return hibernateJpaDialect;
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(dataSource());
entityManagerFactoryBean.setPackagesToScan(new String[]{BaseEntity.class.getPackage().getName()});
entityManagerFactoryBean.setJpaVendorAdapter(hibernateJpaVendorAdapter(dataSourceConfiguration));
entityManagerFactoryBean.setJpaProperties(hibernateProperties(dataSourceConfiguration));
entityManagerFactoryBean.setJpaDialect(hibernateJpaDialect());
return entityManagerFactoryBean;
}
@Bean
public DataSource dataSource() {
return new HikariDataSource(hikariConfig(dataSourceConfiguration));
}
@Bean
public HibernateJpaVendorAdapter hibernateJpaVendorAdapter(DataSourceConfiguration dataSourceConfiguration) {
HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
hibernateJpaVendorAdapter.setDatabase(Database.MYSQL);
hibernateJpaVendorAdapter.setShowSql(Boolean.valueOf(dataSourceConfiguration.getShowsql()));
hibernateJpaVendorAdapter.setGenerateDdl(Boolean.valueOf(dataSourceConfiguration.getDdlGeneration()));
return hibernateJpaVendorAdapter;
}
@Bean
public EclipseLinkJpaVendorAdapter eclipseLinkJpaVendorAdapter(DataSourceConfiguration dataSourceConfiguration) {
EclipseLinkJpaVendorAdapter eclipseLinkJpaVendorAdapter = new EclipseLinkJpaVendorAdapter();
eclipseLinkJpaVendorAdapter.setDatabase(Database.MYSQL);
eclipseLinkJpaVendorAdapter.setShowSql(Boolean.valueOf(dataSourceConfiguration.getShowsql()));
eclipseLinkJpaVendorAdapter.setGenerateDdl(Boolean.valueOf(dataSourceConfiguration.getDdlGeneration()));
return eclipseLinkJpaVendorAdapter;
}
private HikariConfig hikariConfig(DataSourceConfiguration dataSourceConfiguration) {
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setDriverClassName(dataSourceConfiguration.getDriver());
hikariConfig.setJdbcUrl(dataSourceConfiguration.getUrl());
hikariConfig.setUsername(dataSourceConfiguration.getUser());
hikariConfig.setPassword(dataSourceConfiguration.getPassword());
return hikariConfig;
}
private Properties hibernateProperties(DataSourceConfiguration dataSourceConfiguration) {
Properties properties = new Properties();
properties.setProperty("hibernate.hbm2ddl.auto", dataSourceConfiguration.getDdlGeneration());
properties.setProperty("hibernate.dialect", dataSourceConfiguration.getDialect());
properties.setProperty("hibernate.current_session_context_class", dataSourceConfiguration.getCurrentSession());
properties.setProperty("hibernate.show_sql", dataSourceConfiguration.getShowsql());
properties.setProperty("hibernate.format_sql", dataSourceConfiguration.getFormatsql());
properties.setProperty("hibernate.discriminator.ignore_explicit_for_joined", "true");
return properties;
}
Объект:
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Getter
@Setter
@Inheritance(strategy = InheritanceType.JOINED)
//@EqualsAndHashCode(callSuper = true)
@DiscriminatorColumn(name = "person_type")
@Table(name = "persons",
uniqueConstraints = {
@UniqueConstraint(columnNames = {"number, person_type ,company_id"})
},
indexes = {
@Index(name = "person_firstname_index", columnList = "firstname"),
@Index(name = "person_lastname_index", columnList = "lastname"),
@Index(name = "person_first_lastname_index", columnList = "firstname,lastname"),
@Index(name = "person_email_index", columnList = "email"),
@Index(name = "person_number_index", columnList = "number, company_id"),
@Index(name = "person_mobile_index", columnList = "mobile"),
@Index(name = "person_email_mobile_number_index", columnList = "number,email,mobile"),
})
public abstract class Person extends BaseEntity implements ActorProfile {}
Исключение: Ошибка при создании компонента с именем entityManagerFactory, определенным в com.orsbv.hcs.config.HCSRepositoryContext: Вызов метода init не выполнен;вложенное исключение: org.hibernate.AnnotationException: невозможно создать ограничение уникального ключа (число, person_type, company_id) для таблиц person: столбец базы данных 'number, person_type, company_id' не найден.Убедитесь, что вы используете правильное имя столбца, которое зависит от используемой стратегии именования (оно может не совпадать с именем свойства в сущности, особенно для реляционных типов)