Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error after using migrate to spring boot 3.3 #31

Open
yug-soni-diatoz opened this issue Jul 9, 2024 · 5 comments
Open

Compilation error after using migrate to spring boot 3.3 #31

yug-soni-diatoz opened this issue Jul 9, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@yug-soni-diatoz
Copy link

What version of OpenRewrite are you using?

I am using

❯ mvn -v                                                                                                             I
Apache Maven 3.8.7
Maven home: /usr/share/maven
Java version: 17.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-17-openjdk-amd64
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "6.5.0-42-generic", arch: "amd64", family: "unix"

How are you running OpenRewrite?

I am using the Maven command line, and my project is a single module project.

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_3 

What is the smallest, simplest way to reproduce the problem?

package com.sda.java3.ecommerce.domains;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.util.UUID;

@Data
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Cart {

    @Id
    @GeneratedValue(generator = "uuid2")
    @GenericGenerator(name="uuid2", strategy = "uuid2")
    @Column(name = "id", updatable = false, nullable = false)
    @Type(type = "org.hibernate.type.UUIDCharType")
    protected UUID id;

    @ManyToOne
    @JoinColumn(name = "user_id")
    protected User user;

    @ManyToOne
    @JoinColumn(name = "product_id")
    protected Product product;

    protected Integer quantity;
}

What did you expect to see?

corresponding dependency injection in pom.xml file 
and correct import and correct change in the @Type annotation

What did you see instead?

package com.sda.java3.ecommerce.domains;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import org.hibernate.type.UUIDCharType; // error
import jakarta.persistence.*;
import java.util.UUID;

@Data
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Cart {

    @Id
    @GeneratedValue(generator = "uuid2")
    @GenericGenerator(name="uuid2", strategy = "uuid2")
    @Column(name = "id", updatable = false, nullable = false)
    @Type(UUIDCharType.class) // error
    protected UUID id;

    @ManyToOne
    @JoinColumn(name = "user_id")
    protected User user;

    @ManyToOne
    @JoinColumn(name = "product_id")
    protected Product product;

    protected Integer quantity;
}

What is the full stack trace of any errors you encountered?

/home/yug/DiatozProjects/E2EHiring/OpenRewrite/E-Commerce-Thymeleaf-SpringBoot-Projec-Diatoz/src/main/java/com/sda/java3/ecommerce/domains/Cart.java:9:26
java: cannot find symbol
  symbol:   class UUIDCharType
  location: package org.hibernate.type
/home/yug/DiatozProjects/E2EHiring/OpenRewrite/E-Commerce-Thymeleaf-SpringBoot-Projec-Diatoz/src/main/java/com/sda/java3/ecommerce/domains/Cart.java:24:11
java: cannot find symbol
  symbol:   class UUIDCharType
  location: class com.sda.java3.ecommerce.domains.Cart
@yug-soni-diatoz yug-soni-diatoz added the bug Something isn't working label Jul 9, 2024
@timtebeek timtebeek added the question Further information is requested label Jul 9, 2024
@timtebeek
Copy link
Contributor

As discussed on Slack: it would be great if you could provide an example of what the manual change was that you had to make to get things working, and fill that in under "What did you expect to see?". Perhaps linking the relevant parts of their migration guide. That way we have something to work towards, as right now I wouldn't know what to do, since I haven't used Hibernate in a while.

@yug-soni-diatoz
Copy link
Author

The conversion should happen like this as per hibernate migration guide to 6
https://docs.jboss.org/hibernate/orm/6.0/migration-guide/migration-guide.html

before

@Type(type="yes_no")
boolean isActive;

after

@Convert(converter=YesNoConverter.class)
boolean isActive;

and this dependency should be injected to the pom.xml

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>6.0.0.Final</version>
        </dependency>

I am still looking into, what's the exact conversion for the UUIDCharType

@timtebeek timtebeek removed the question Further information is requested label Jul 10, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Jul 10, 2024
@yug-soni-diatoz
Copy link
Author

@timtebeek , Can you please help me finding the exact recipe which modified the hibernate related code in my case.
image

@yug-soni-diatoz
Copy link
Author

After my research this is exact expected changes
image

@timtebeek
Copy link
Contributor

It's likely to have been this recipe

public class TypeAnnotationParameter extends Recipe {
private static final AnnotationMatcher FQN_TYPE_ANNOTATION = new AnnotationMatcher("@org.hibernate.annotations.Type");
@Override
public String getDisplayName() {
return "@Type annotation type parameter migration";
}
@Override
public String getDescription() {
return "Hibernate 6.x has 'type' parameter of type String replaced with 'value' of type class.";
}

Any time you run the Maven or Gradle plugin it should output which files where changed by which recipes, so I'd expect to see the same there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

2 participants