13

Hello StackOverflow Community,

Attempted:

Upgrading Spring Boot from 2.7.5 to 3.0.0, which uses Hibernate ORM core version 6.1.5.Final

Entity

Plant.java

@Data
@Entity
public class Plant {

    @Id
    Long id;

    String name;

    @OneToMany(mappedBy = "plant")
    List<Branch> branches;

}

Branch.java

@Data
@Entity
public class Branch {

    @Id
    Long id;

    String name;

    @ManyToOne
    Plant plant;

}

VPlantUI.java

@Entity
@Immutable
public class VPlantUI {

    @Id
    Long id;

    String name;

    @OneToMany(mappedBy = "plant")
    List<Branch> branches;
    
    // joins, fields from other tables

}

Issue:

Caused by: org.hibernate.sql.ast.tree.from.UnknownTableReferenceException: Unable to determine TableReference (`plant`) for `ca.demo.model.view.VPlantUI.branches.{fk-target}`

Question:

I'm attempting to map VPlantUI to a view in the database.

Spring Boot v2.7.5, Spring v5.3.23, Hibernate ORM core version 5.6.12.Final did not have any issue with this type of mapping however Spring Boot v3.0.0, Spring v6.0.2, Hibernate ORM core version 6.1.5.Final doesn't allow this type of mapping.

What are the alternatives/options to map VPlantUI to Branch?

3
  • I have same problem since migrating spring boot to 3 & hibernate to 6. also same problem there: github.com/spring-projects/spring-data-jpa/issues/…
    – asyncmind
    Commented Apr 11, 2023 at 9:02
  • Did you find a solution? Updating to hibernate-core 6.2.0 or higher doesn't seem to work.
    – Matt
    Commented May 15, 2023 at 9:03
  • I upgraded to spring-boot-starter-parent:3.1.0 which uses hibernate-core:6.2.2.Final and I have a different error now. Caused by: org.hibernate.AnnotationException: Association 'ca.demo.model.view.VPlantUI.branches' is 'mappedBy' a property named 'plant' which references the wrong entity type 'ca.demo.model.Plant', expected 'ca.demo.model.view.VPlantUI'
    – MrC0mm0n
    Commented May 21, 2023 at 2:31

2 Answers 2

0

According to this jira it worked for me with version 6.2.0.Final of hibernate-core

0

You should use @JoinColumn. Here is an example:

@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
@JoinColumn(name = "fk_plant_id", updatable = true, insertable= true)
private Plant plant;

Not the answer you're looking for? Browse other questions tagged or ask your own question.