org.hibernate.MappingException: Could not determine type for: java.util.Set [duplicate]

I got the same problem with @ManyToOne column. It was solved… in stupid way. I had all other annotations for public getter methods, because they were overridden from parent class. But last field was annotated for private variable like in all other classes in my project. So I got the same MappingException without the reason. … Read more

JPA: difference between @JoinColumn and @PrimaryKeyJoinColumn?

What happens if I promote the column to be a/the PK, too (a.k.a. identifying relationship)? As the column is now the PK, I must tag it with @Id (…). This enhanced support of derived identifiers is actually part of the new stuff in JPA 2.0 (see the section 2.4.1 Primary Keys Corresponding to Derived Identities … Read more

spring data jpa @query and pageable

You can use pagination with a native query. It is documented here: Spring Data JPA – Reference Documentation “You can however use native queries for pagination by specifying the count query yourself: Example 59. Declare native count queries for pagination at the query method using @Query“ public interface UserRepository extends JpaRepository<User, Long> { @Query(value = … Read more

Spring boot Hibernate error “Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set” when working with multiple data sources

I figure it out. Modify method entityManagerFactory for both Db2Configuration and OracleConfiguration to supply them with the information about hibernate dialect: for DB2 @Primary @Bean(name = “db2EntityManagerFactory”) public LocalContainerEntityManagerFactoryBean entityManagerFactory( EntityManagerFactoryBuilder builder , @Qualifier(“db2DataSource”) DataSource dataSource) { final HashMap<String, Object> hibernateProperties = new HashMap<String, Object>(); hibernateProperties.put(“hibernate.dialect”, “org.hibernate.dialect.DB2390Dialect”); return builder .dataSource(dataSource) .packages(“project.dataconfig.db2.entity”) .properties(hibernateProperties) .persistenceUnit(“db2persistanceunit”) .build(); } … Read more

Is it possible to have autoincrement number without it being an ID?

I see the following options: 1) You can use @Generated annotation. You should have a table declared in the following way: create sequence TST_DATA_SEQ increment by 1 start with 1; create table TST_DATA ( … dat_auto integer default nextval(‘TST_DATA_SEQ’), … ); and appropriate column in the entity: @Generated(value = GenerationTime.INSERT) @Column(name = “dat_auto”, insertable = … Read more

Hibernate ID Generator

A cursory search of Google for ‘hibernate custom id generator tutorial’ turned up the following possibilities. I’ve excluded those that don’t look useful and summarized the content of each. http://www.devx.com/Java/Article/30396 – covers the issues of generating an ID before the data is persisted (and hence does not yet have a business key). http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#mapping-declaration – the … Read more

Access to Session using Spring JPA and Hibernate in order to enable filters

I ended up with AOP solution : @Aspect @Component public class EnableFilterAspect { @AfterReturning( pointcut=”bean(entityManagerFactory) && execution(* createEntityManager(..))”, returning=”retVal”) public void getSessionAfter(JoinPoint joinPoint, Object retVal) { if (retVal != null && EntityManager.class.isInstance(retVal)) { Session session = ((EntityManager) retVal).unwrap(Session.class); session.enableFilter(“myFilter”).setParameter(“myParameter”, “myValue”); } } }