Git Product home page Git Product logo

issue-hhh-14590-missing-join-with-embeddable's Introduction

Reproducer for https://hibernate.atlassian.net/browse/HHH-14590

== Join not rendered when requested for embedded in secondary table if a single column is selected using the Criteria API

Related Spring Data issue: spring-projects/spring-data-jpa#2209

Given the following entities

@SecondaryTable(name = "secondary")
@Entity
public class RootEntity {
@Id
@GeneratedValue
Long id;

	String rootValue;

	@Embedded
	PlainEmbeddable plainEmbeddable;

	@Embedded
	SecondTableEmbeddable secondaryEmbeddable;
}
@Embeddable
public class PlainEmbeddable {
String plainName;
String plainValue;
}
@Embeddable
public class SecondTableEmbeddable {
@Column(table = "secondary")
String secName;
@Column(table = "secondary")
String secValue;
}

This query fails because it renders a SQL statement with a missing join:

CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> query = builder.createQuery(Long.class);
Root<RootEntity> root = query.from(RootEntity.class);

		Join<Object, Object> join = root.join("secondaryEmbeddable");

		Path<Object> name = join.get("secName");

		query.select(root.get("id")).where(builder.equal(name, "secondary"));

		em.createQuery(query).getSingleResult();

The rendered select is (Note the missing join and the wrong table used for secName):

select
rootentity0_.id as col_0_0_
from
RootEntity rootentity0_
where
rootentity0_1_.secName=?

The following variants work fine:

Embeddable not stored in secondary table

CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> query = builder.createQuery(Long.class);
Root<RootEntity> root = query.from(RootEntity.class);

Join<Object, Object> join = root.join("plainEmbeddable");  // <<=== !!!!!!!!

Path<Object> name = join.get("plainName");

query.select(root.get("id")).where(builder.equal(name, "primary"));

em.createQuery(query).getSingleResult();

Selecting the full entity

CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<RootEntity> query = builder.createQuery(RootEntity.class);
Root<RootEntity> root = query.from(RootEntity.class);

Join<Object, Object> join = root.join("secondaryEmbeddable");

Path<Object> name = join.get("secName");

query.select(root).where(builder.equal(name, "secondary")); // <<=== !!!!!!!!

em.createQuery(query).getSingleResult();

Using a path instead of a join

CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Long> query = builder.createQuery(Long.class);
Root<RootEntity> root = query.from(RootEntity.class);

Path<Object> path = root.get("secondaryEmbeddable"); // <<=== !!!!!!!!

Path<Object> name = path.get("secName");

query.select(root.get("id")).where(builder.equal(name, "secondary"));

em.createQuery(query).getSingleResult();

issue-hhh-14590-missing-join-with-embeddable's People

Contributors

schauder avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.