[JIRA] (HHH-16858) Can't compare test expression of type [BasicSqmPathSource(type : Enum)] with element of type [basicType@5(java.lang.Integer,4)]
by Jonas Gernot Steinke (JIRA)
Jonas Gernot Steinke ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=712020%... ) *commented* on HHH-16858 ( https://hibernate.atlassian.net/browse/HHH-16858?atlOrigin=eyJpIjoiYTk3Zm... )
Re: Can't compare test expression of type [BasicSqmPathSource(type : Enum)] with element of type [basicType(a)5(java.lang.Integer,4)] ( https://hibernate.atlassian.net/browse/HHH-16858?atlOrigin=eyJpIjoiYTk3Zm... )
The comparison with < in this example is only to show that comparison operators ( = , < , > , >= , <= , <> ) do not work in this case.
In the example I use EnumType.ORDINAL , in the other case of EnumType ( https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibern... ) EnumType.STRING a similar error occurs:
Error interpreting query [SELECT b FROM ItemB b WHERE b.type = 'B2']; this may indicate a semantic (user query) problem or a bug in the parser [SELECT b FROM ItemB b WHERE b.type = 'B2']
Can't compare test expression of type [BasicSqmPathSource(type : Enum)] with element of type [basicType(a)15(java.lang.String,12)]
The question is, why does it work with ItemA:
public interface ItemARepository extends JpaRepository<ItemA, Long >, JpaSpecificationExecutor<ItemA> {
@Query( "SELECT a FROM ItemA a WHERE a.type < 1" )
List<ItemA> findAllByTypeA2();
}
https://github.com/JGSteinke/hibernate-test/blob/main/src/main/java/de/hi...
As I wrote before, it has only stopped working since the Hibernate update. My guess is that in case A the enum is compared depending on the EnumType ( EnumType.ORDINAL as Integer or EnumType.STRING as String) and in case B this does not happen.
The question of sense of compare enums using < is not at issue here, but I would like to discuss it briefly. In this way you can, for example, find all entries that precede a certain status.
( https://hibernate.atlassian.net/browse/HHH-16858#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16858#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#100227- sha1:3bc807d )
1 year, 6 months
[JIRA] (HHH-16860) OneToMany with inherited classes on both sides
by Rob Scala (JIRA)
Rob Scala ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNzY2MzM3YTdj... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16860?atlOrigin=eyJpIjoiNzY2Mz... ) HHH-16860 ( https://hibernate.atlassian.net/browse/HHH-16860?atlOrigin=eyJpIjoiNzY2Mz... ) OneToMany with inherited classes on both sides ( https://hibernate.atlassian.net/browse/HHH-16860?atlOrigin=eyJpIjoiNzY2Mz... )
Change By: Rob Scala ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
I have two base classes, company and computer_system. Each of the base classes has two subclasses, and they use the InheritanceType.JOINED strategy.
!company_computer_systems.png|width=879,height=232!
Each computer system has a company owner. A customer_computer_system is owned by a customer_company and a distributor_computer_system is owned by a distributor_company.
{noformat}@Entity ...
@Inheritance(strategy= InheritanceType.JOINED)
public abstract class ComputerSystem {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "OWNER_ID", foreignKey = @ForeignKey())
protected Company owner;
}
{noformat}
One of the company subclasses has a OneToMany collection with one of the computer_system subclasses.
{noformat}@Entity ...
public class CustomerCompany {
@OneToMany(mappedBy = "owner", orphanRemoval = true, cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
private List<CustomerComputerSystem> computerSystems;
}
{noformat}
With this mapping, I am able to access the list of computer systems.
The problem is that when I use the schema migrator tool to produce an update script, it creates this:
{noformat}alter table if exists customer_computer_system add column OWNER_ID bigint;
alter table if exists distributor_computer_system add column OWNER_ID bigint;{noformat}
It wants to add “id” fields to the ComputerSystem subclasses.
The test case is attached and is also here - [https://github.com/robscala/onetomany_inherited_test_case|https://github....]
[^HHH-16860.zip]
One thing go note. This test case properly shows the problem in Hibernate 6.2.1, but fails to create the EMF in later versions due to an assertion error in the SimpleForeignKeyDescriptor. If I turn off assertions, the test case completes even in version 6.3.0-SNAPSHOT, showing the same incorrect update script.
( https://hibernate.atlassian.net/browse/HHH-16860#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16860#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#100227- sha1:3bc807d )
1 year, 6 months
[JIRA] (HHH-16860) OneToMany with inherited classes on both sides
by Rob Scala (JIRA)
Rob Scala ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNzczZjZmYzZl... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16860?atlOrigin=eyJpIjoiNzczZj... ) HHH-16860 ( https://hibernate.atlassian.net/browse/HHH-16860?atlOrigin=eyJpIjoiNzczZj... ) OneToMany with inherited classes on both sides ( https://hibernate.atlassian.net/browse/HHH-16860?atlOrigin=eyJpIjoiNzczZj... )
Issue Type: Bug Affects Versions: 6.2.1, 6.2.5 Assignee: Unassigned Attachments: company_computer_systems.png Components: hibernate-core Created: 27/Jun/2023 10:32 AM Priority: Major Reporter: Rob Scala ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
I have two base classes, company and computer_system. Each of the base classes has two subclasses, and they use the InheritanceType.JOINED strategy.
Each computer system has a company owner. A customer_computer_system is owned by a customer_company and a distributor_computer_system is owned by a distributor_company.
@Entity ...
@Inheritance(strategy= InheritanceType.JOINED)
public abstract class ComputerSystem {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "OWNER_ID", foreignKey = @ForeignKey())
protected Company owner;
}
One of the company subclasses has a OneToMany collection with one of the computer_system subclasses.
@Entity ...
public class CustomerCompany {
@OneToMany(mappedBy = "owner", orphanRemoval = true, cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
private List<CustomerComputerSystem> computerSystems;
}
With this mapping, I am able to access the list of computer systems.
The problem is that when I use the schema migrator tool to produce an update script, it creates this:
alter table if exists customer_computer_system add column OWNER_ID bigint;
alter table if exists distributor_computer_system add column OWNER_ID bigint;
It wants to add “id” fields to the ComputerSystem subclasses.
The test case is attached and is also here - https://github.com/robscala/onetomany_inherited_test_case
One thing go note. This test case properly shows the problem in Hibernate 6.2.1, but fails to create the EMF in later versions due to an assertion error in the SimpleForeignKeyDescriptor. If I turn off assertions, the test case completes even in version 6.3.0-SNAPSHOT, showing the same incorrect update script.
( https://hibernate.atlassian.net/browse/HHH-16860#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16860#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#100227- sha1:3bc807d )
1 year, 6 months