kaW
kaW

Reputation: 23

How to save input given in following json format to database in spring boot

I'm creating an example student registration system and I want to input data in the following format through postman.

{
    "schemeName":"Scheme one",
    "type":"Level1",
    "paymentplan" : [
        {"feeType": "reg" , "amount": 2000}, 
        {"feeType": "reg" , "amount": 2000}, 
         {"feeType": "reg" , "amount": 2000}
    ]

}

Here are my paymentScheme and Student classes.

I've modified my PaymentScheme class as follows.

@Entity
@Table(name = "payment_scheme")
public class PaymentScheme {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "scheme_id")
    private Integer schemeId; // primary key: scheme

    @Column(name = "scheme_name")
    private String schemeName;

    private String schemeType;

    @ElementCollection
    @CollectionTable(name = "payment_plan", joinColumns = @JoinColumn(name = "scheme_id"))
    private List<Map<String, String>> paymentPlan;

But I'm getting these errors.

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'applicationConfig' defined in file [C:\Users\Agathisi\Desktop\sms-testing3\target\classes\com\example\config\ApplicationConfig.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'userRepository' defined in com.example.user.UserRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaSharedEM_entityManagerFactory' while setting bean property 'entityManager'
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Could not determine recommended JdbcType for java.util.Map<java.lang.String, java.lang.String>
Caused by: org.hibernate.type.descriptor.java.spi.JdbcTypeRecommendationException: Could not determine recommended JdbcType for java.util.Map<java.lang.String, java.lang.String>

I want to make this happen without creating another class named PaymentPlan. Can someone please help me with this..?

Upvotes: 0

Views: 55

Answers (0)

Related Questions