[JIRA] (HHH-16892) LocalXmlResourceResolver does not resolve dtd URLs that use https scheme
by Thirunavukarasu Thulasi (JIRA)
Thirunavukarasu Thulasi ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMzNlMjA5ZWRi... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16892?atlOrigin=eyJpIjoiMzNlMj... ) HHH-16892 ( https://hibernate.atlassian.net/browse/HHH-16892?atlOrigin=eyJpIjoiMzNlMj... ) LocalXmlResourceResolver does not resolve dtd URLs that use https scheme ( https://hibernate.atlassian.net/browse/HHH-16892?atlOrigin=eyJpIjoiMzNlMj... )
Issue Type: Bug Affects Versions: 5.6.6 Assignee: Yoann Rodière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) Attachments: image-20230705-030300.png Components: hibernate-core Created: 04/Jul/2023 20:24 PM Priority: Major Reporter: Thirunavukarasu Thulasi ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%... )
*Background*
As per the following recommendation, we had updated all our hibernate mapping files to refer dtd files with https scheme
The markup declarations contained or pointed to by the document type declaration must be well-formed - Hibernate ORM - Hibernate ( https://discourse.hibernate.org/t/the-markup-declarations-contained-or-po... )
i,e we had updated our hibernate mapping files to use the recommended dtd urls
updated existing urls from
http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd ( http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd%22 )
to
*https* ( https://hibernate.org/dtd/hibernate-mapping-3.0.dtd%22 ) [://hibernate.org/dtd/hibernate-mapping-3.0.dtd|https://hibernate.org/dtd/hibernate-mapping-3.0.dtd%22]
Also, we had upgraded hibernate version to version 5.6.6 (which has a fix HHH-15094 ( https://hibernate.atlassian.net/browse/HHH-15094 ) Closed )
*Problem*
Hibernate does not resolve dtd files locally when using *https* scheme,
But, it resolves the dtd files locally when using *http* scheme
*Analysis*
Following is a snippet of code from LocalXmlResourceResolver,
When *HTTP* scheme is used, Hibernate uses *startsWith* to compare with the identifierBase,
But, when *HTTPS* scheme is used, Hibernate uses *matches* to compare with the identiferBase
For example,
Consider a hibernate mapping file with the following DOCTYPE (changed as per above recommendation)
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
" https://hibernate.org/dtd/hibernate-mapping-3.0.dtd" ( https://hibernate.org/dtd/hibernate-mapping-3.0.dtd%22 ) >
In the LocalXmlResourceResolver, The condition which checks whether to return local resource, fails and returns false when https scheme is used
i,e
if ( systemId.startsWith( httpBase )
systemId.matches( httpsBase ) ) { return true; }
checks as follows
" https://hibernate.org/dtd/hibernate-mapping-3.0.dtd" ( https://hibernate.org/dtd/hibernate-mapping-3.0.dtd%22 ).matches( "hibernate.org/dtd/hibernate-mapping" )
which returns *false*
*Proposed solution*
* Change systemId. *matches* () to either systemId. *startsWith()* or systemId. *contains()*
( https://hibernate.atlassian.net/browse/HHH-16892#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16892#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100229- sha1:634ba05 )
2 years, 6 months
[JIRA] (HHH-16885) Hibernate 6.1.6 changes outer to inner join when @EntityGraph and @Id
by Konrad Wajs (JIRA)
Konrad Wajs ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5dea973... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZjdjZWIyZGE1... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16885?atlOrigin=eyJpIjoiZjdjZW... ) HHH-16885 ( https://hibernate.atlassian.net/browse/HHH-16885?atlOrigin=eyJpIjoiZjdjZW... ) Hibernate 6.1.6 changes outer to inner join when @EntityGraph and @Id ( https://hibernate.atlassian.net/browse/HHH-16885?atlOrigin=eyJpIjoiZjdjZW... )
Change By: Konrad Wajs ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5dea973... )
I'm using @EntityGraph to eagerly load some attributes.
However, something broke after updating hibernate-core from 6.1.5.Final to 6.1.6.Final
Suppose we have a human who can have multiple houses:
{code:java}public class Human {
@Id
@Column(name = "ID", nullable = false, updatable = false, precision = 20)
@GeneratedValue
private BigInteger id;
@EqualsAndHashCode.Exclude
@ToString.Exclude
@OneToMany(mappedBy = "human", cascade = CascadeType.ALL)
@OnDelete(action = OnDeleteAction.CASCADE)
private Collection<House> houses;
}{code}
When searching for a human, by ID, EntityGraph can eagerly load some attributes:
{code:java}@EntityGraph(attributePaths = { "houses.address" })
@Query ("SELECT h FROM Human h WHERE h.id = ?1")
Human findByIdEagerHouseAddresses(Integer id);{code}
This will create SQL with left (outer by default) joins:
{code:sql}select h1_0.id, h2_0.human_fk, h2_0.address_fk, a1_0.id
from human h1_0
left join house h2_0 on h1_0.id = h2_0.human_fk
left join address a1_0 on a1_0.id = h2_0.address_fk where h1_0.id in (?){code}
This is acceptable because I will get the human even if they don't have a house.
However, if the address field in the house has the @Id annotation, the outer join will change to "inner":
{code:java}@Entity
public class House {
@Id
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "human_fk", nullable = false, updatable = false)
private Human human;
@Id // THIS ANNOTATION WAS ADDED
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "address_fk", nullable = false, updatable = false)
private Address address;
}{code}
{code:sql}select h1_0.id, h2_0.human_fk, h2_0.address_fk, a1_0.id
from human h1_0
left join house h2_0 on h1_0.id = h2_0.human_fk
join address a1_0 on a1_0.id = h2_0.address_fk where h1_0.id in (?){code}
If a human does not have a house, the query returns nothing due to the inner join, which seems like a bug.
( https://hibernate.atlassian.net/browse/HHH-16885#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16885#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100229- sha1:634ba05 )
2 years, 6 months
[JIRA] (HHH-16885) Hibernate 6.1.6 changes outer to inner join when @EntityGraph and @Id
by Konrad Wajs (JIRA)
Konrad Wajs ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5dea973... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZDc5YWYzMGUw... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16885?atlOrigin=eyJpIjoiZDc5YW... ) HHH-16885 ( https://hibernate.atlassian.net/browse/HHH-16885?atlOrigin=eyJpIjoiZDc5YW... ) Hibernate 6.1.6 changes outer to inner join when @EntityGraph and @Id ( https://hibernate.atlassian.net/browse/HHH-16885?atlOrigin=eyJpIjoiZDc5YW... )
Change By: Konrad Wajs ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5dea973... )
I'm using @EntityGraph to eagerly load some attributes.
However, something broke after updating from 6.1. 5. x Final to 6. x 1. 6.Final
Suppose we have a human who can have multiple houses:
{code:java}
public class Human {
@Id
@Column(name = "ID", nullable = false, updatable = false, precision = 20)
@GeneratedValue
private BigInteger id;
@EqualsAndHashCode.Exclude
@ToString.Exclude
@OneToMany(mappedBy = "human", cascade = CascadeType.ALL)
@OnDelete(action = OnDeleteAction.CASCADE)
private Collection<House> houses;
}
{code}
When searching for a human, by ID, EntityGraph can eagerly load some attributes:
{code:java}
@EntityGraph(attributePaths = { "houses.address" })
@Query ("SELECT h FROM Human h WHERE h.id = ?1")
Human findByIdEagerHouseAddresses(Integer id);
{code}
This will create SQL with left (outer by default) joins:
{code:sql}
select h1_0.id, h2_0.human_fk, h2_0.address_fk, a1_0.id
from human h1_0
left join house h2_0 on h1_0.id = h2_0.human_fk
left join address a1_0 on a1_0.id = h2_0.address_fk where h1_0.id in (?)
{code}
This is acceptable because I will get the human even if they don't have a house.
However, if the address field in the house has the @Id annotation, the outer join will change to "inner":
{code:java}
@Entity
public class House {
@Id
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "human_fk", nullable = false, updatable = false)
private Human human;
@Id // THIS ANNOTATION WAS ADDED
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "address_fk", nullable = false, updatable = false)
private Address address;
}
{code}
{code:sql}
select h1_0.id, h2_0.human_fk, h2_0.address_fk, a1_0.id
from human h1_0
left join house h2_0 on h1_0.id = h2_0.human_fk
join address a1_0 on a1_0.id = h2_0.address_fk where h1_0.id in (?)
{code}
If a human does not have a house, the query returns nothing due to the inner join, which seems like a bug.
( https://hibernate.atlassian.net/browse/HHH-16885#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16885#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100229- sha1:634ba05 )
2 years, 6 months