Showing posts with label JPA. Show all posts
Showing posts with label JPA. Show all posts

Thursday 22 September 2022

java.lang.IllegalStateException: org.hibernate.TransientObjectException: object references an unsaved transient instance

 Hello All,

Today I'm sharing my learning experience, to solve the one issue while working with Springboot & Hibernate/JPA.

We often get the below error.


org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.oracle.dto.Asset
	at org.hibernate.engine.internal.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:347) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]


The solution of this issue is to explicitly save the referred data.

I've solved this issue with the below code.


Transaction tx=session.beginTransaction();
        session.save(citizen);
        for (Asset asset:citizen.getAssetList()) {
            session.save(asset);
        }
        tx.commit();

Friday 16 September 2022

SpringBoot disable all default database related configuration.

 Hi Folks,

Today, I'm sharing my working experience to disable the default springboot database related configuration.

This can be achieved via two mechanism.

Mechanism 1: Annotations

@SpringBootApplication
@EnableAutoConfiguration(exclude = {
    DataSourceAutoConfiguration.class,
    DataSourceTransactionManagerAutoConfiguration.class,
    HibernateJpaAutoConfiguration.class})
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
}


Mechanism 2 : application.properties.
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration

A Guide to Installing Oracle HR Schema on an Existing Docker Container

  Hi Reader, Today I want to share my learning on how to install Oracle HR schema on a existing docker container. Step 1: Download the verif...