How to configure Spring without persistence.xml?

From Spring Guide Accessing Data with JPA @Configuration @EnableJpaRepositories public class Application { @Bean public DataSource dataSource() { return new EmbeddedDatabaseBuilder().setType(H2).build(); } @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) { LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean(); lef.setDataSource(dataSource); lef.setJpaVendorAdapter(jpaVendorAdapter); lef.setPackagesToScan(“hello”); return lef; } @Bean public JpaVendorAdapter jpaVendorAdapter() { HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter(); hibernateJpaVendorAdapter.setShowSql(false); hibernateJpaVendorAdapter.setGenerateDdl(true); hibernateJpaVendorAdapter.setDatabase(Database.H2); return … Read more

PostgreSQL/JDBC and TIMESTAMP vs. TIMESTAMPTZ

Generally use TIMESTAMPTZ Here’s advice from David E. Wheeler, a Postgres expert, in a blog post whose title says it all:Always Use TIMESTAMP WITH TIME ZONE (TIMESTAMPTZ) If you are tracking actual moments, specific points on the timeline, use TIMESTAMP WITH TIME ZONE. One Exception: Partitioning Wheeler’s sole exception is when partitioning on timestamps, because … Read more

org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: USERS, for columns: [org.hibernate.mapping.Column(invoices)]

If I remember correctly, Hibernate doesn’t let you mix and match annotation in conjunction with field / getter. If your @Id annotation is set over a field, all your mappings should follow fields. Try moving @OneToMany @JoinColumn(name=”INVOICE_ID”, nullable=false) from getInvoices() to private Set<Invoice> invoices; This pattern should be applied to your Invoice class as well

Spring JPA Repository – Operator SIMPLE_PROPERTY on jsonObject requires a scalar argument

I encountered this same problem. I worked around it by changing the name of my method by adding “In” to the end of it. For your example, it would be findAllByTagsIn(java.util.Set) See the “supported keywords inside method names” table here: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation

What is the use of @Transactional with JPA and Hibernate?

@Transactional annotation is used when you want the certain method/class(=all methods inside) to be executed in a transaction. Let’s assume user A wants to transfer 100$ to user B. What happens is: We decrease A’s account by 100$ We add 100$ to B’s account Let’s assume the exception is thrown after succeeding 1) and before … Read more

Powermock and Spring cause ConversionException when injecting EntityManager in test

I had a similar issue and it was suggested to me to create a Resources.java class that Produced an Entity Manager. @Stateful public class Resources implements Serializable { @PersistenceContext (type = PersistenceContextType.TRANSACTION) private EntityManager entityManager; @Produces public EntityManager getEntityManager() { return entityManager; } } I’m still not exactly sure why this solution worked for me… … Read more

How to enable batch inserts with Hibernate and Spring Boot

There is nothing wrong with your code and it’s working properly. I debugged it and then I installed p6spy and it’s working. This is how you can test it too: In build.gradle add this dependency: compile ‘p6spy:p6spy:2.1.4’ Modify the connection properties like this: database.driver=com.p6spy.engine.spy.P6SpyDriver database.url=jdbc:p6spy:postgresql://localhost:5432/ Add spy.properties in the resources folder. You can download it … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)