How to fix the Hibernate “object references an unsaved transient instance – save the transient instance before flushing” error

You should include cascade=”all” (if using xml) or cascade=CascadeType.ALL (if using annotations) on your collection mapping. This happens because you have a collection in your entity, and that collection has one or more items which are not present in the database. By specifying the above options you tell hibernate to save them to the database when saving their parent.

org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set

First remove all of your configuration Spring Boot will start it for you. Make sure you have an application.properties in your classpath and add the following properties. If you really need access to a SessionFactory and that is basically for the same datasource, then you can do the following (which is also documented here although for XML, not JavaConfig). That way … Read more

How does spring.jpa.hibernate.ddl-auto property exactly work in Spring?

For the record, the spring.jpa.hibernate.ddl-auto property is Spring Data JPA specific and is their way to specify a value that will eventually be passed to Hibernate under the property it knows, hibernate.hbm2ddl.auto. The values create, create-drop, validate, and update basically influence how the schema tool management will manipulate the database schema at startup. For example, the update operation will query the JDBC driver’s API to … Read more

org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set

First remove all of your configuration Spring Boot will start it for you. Make sure you have an application.properties in your classpath and add the following properties. If you really need access to a SessionFactory and that is basically for the same datasource, then you can do the following (which is also documented here although for XML, not JavaConfig). That way … Read more

What is difference between CrudRepository and JpaRepository interfaces in Spring Data JPA?

JpaRepository extends PagingAndSortingRepository which in turn extends CrudRepository. Their main functions are: CrudRepository mainly provides CRUD functions. PagingAndSortingRepository provides methods to do pagination and sorting records. JpaRepository provides some JPA-related methods such as flushing the persistence context and deleting records in a batch. Because of the inheritance mentioned above, JpaRepository will have all the functions of CrudRepository and PagingAndSortingRepository. So if you don’t need the repository to … Read more

org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set

First remove all of your configuration Spring Boot will start it for you. Make sure you have an application.properties in your classpath and add the following properties. If you really need access to a SessionFactory and that is basically for the same datasource, then you can do the following (which is also documented here although for XML, not JavaConfig). That way … Read more