0

Configuration configuration = new Configuration(); configuration.addAttributeConverter(new BirthdayConverter());

    **configuration.registerTypeOverride(new JsonBinaryType());

** // It doesnt work

    configuration.configure();

    try (SessionFactory sessionFactory = configuration.buildSessionFactory();
         Session session = sessionFactory.openSession()) {

        session.beginTransaction();
        User user = User.builder()
                .username("[email protected]")
                .firstname("John")
                .lastname("Jones")
                .info("""
                        {
                        "name": "John",  
                        "id": 25   
                        }
                        """)
                .birthdate(new Birthday(LocalDate.of(1998, 6, 21)))
                .role(Role.ADMIN)
                .build();
        session.persist(user);

        session.getTransaction().commit();

entity/User.class

//@Type(type = "com.vladmihalcea.hibernate.type.json.JsonBinaryType")
@Convert(converter = JsonBinaryType.class) 
private String info;

}

Always getting Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.JsonSerializer

Changed @Type(type = "com.vladmihalcea.hibernate.type.json.JsonBinaryType") to @Convert(converter = JsonBinaryType.class)

5
  • dependencies { implementation 'org.hibernate.orm:hibernate-core:6.3.1.Final' implementation("org.postgresql:postgresql:42.6.0") implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.5.6' annotationProcessor 'org.springframework.boot:spring-boot-starter-data-jpa:2.5.6' implementation 'com.vladmihalcea:hibernate-types-parent:2.10.3' implementation 'com.vladmihalcea:hibernate-types-52:2.21.1' implementation 'org.slf4j:slf4j-api:2.0.7' } Commented Oct 3, 2023 at 18:55
  • Welcome to Stack Overflow. Please take the tour to learn how Stack Overflow works and read How to Ask on how to improve the quality of your question. Then check the help center to see what questions you can ask. Commented Oct 3, 2023 at 18:56
  • Please try adding implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.0.1' to your gradle file. or in your syntax implementation "com.fasterxml.jackson.core:jackson-databind:2.0.1" Commented Oct 3, 2023 at 18:59
  • Added. Now getting: Exception in thread "main" java.lang.NoSuchMethodError: 'void org.hibernate.type.AbstractSingleColumnStandardBasicType.<init>(org.hibernate.type.descriptor.sql.SqlTypeDescriptor, org.hibernate.type.descriptor.java.JavaTypeDescriptor)' at com.vladmihalcea.hibernate.type.AbstractHibernateType.<init>(AbstractHibernateType.java:27) at com.vladmihalcea.hibernate.type.json.JsonBinaryType.<init>(JsonBinaryType.java:36) at com.vladmihalcea.hibernate.type.json.JsonBinaryType.<clinit>(JsonBinaryType.java:33) Commented Oct 3, 2023 at 20:21
  • try reading up here - stackoverflow.com/questions/38407235/… Commented Oct 3, 2023 at 23:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.