[JIRA] (HHH-16859) max() doesn't work with Enums
by Gavin King (JIRA)
Gavin King ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *commented* on HHH-16859 ( https://hibernate.atlassian.net/browse/HHH-16859?atlOrigin=eyJpIjoiMjg3MD... )
Re: max() doesn't work with Enums ( https://hibernate.atlassian.net/browse/HHH-16859?atlOrigin=eyJpIjoiMjg3MD... )
It doesn’t make sense because enums aren’t usually ordered types, and because whatever ordering they may have is lost if you map them with @Enumerated(STRING) , which is the mapping I think is strongly preferable.
(Persisting an enum as an integer is something that's just a bit too hostile to anyone else who comes along and tries to make sense of the data.)
Anyway, this isn't just my opinion: if you check sections *4.8.5* and *4.6.7* of the JPA spec, you’ll see that enums are quite explicitly not valid operands of < or legal arguments of aggregate functions like max().
Now, sure Hibernate used to accept a lot of not-very-well-typed HQL and let the database sort it out. We don’t do that anymore, since it was a source of bad error messages and lots of portability problems. HQL is now much more typesafe, and you’re just going to have to get used to that.
And, for the record, we’re totally within our rights to make deliberate changes like this in a major version. That’s why it’s called “Hibernate six” and not “Hibernate five dot seven”. So drop the attitude please.
On the other hand, I agree that it would be nice to mention this in the migration guide.
I frankly don’t even know what the big deal is when there’s a rather trivial and perfectly natural workaround: max(cast(enum as Integer)).
( https://hibernate.atlassian.net/browse/HHH-16859#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16859#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:534ec1c )
2 years, 9 months
[JIRA] (HHH-16859) max() doesn't work with Enums
by Michał Maliszewski (JIRA)
Michał Maliszewski ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ad7619... ) *commented* on HHH-16859 ( https://hibernate.atlassian.net/browse/HHH-16859?atlOrigin=eyJpIjoiNDU1Yz... )
Re: max() doesn't work with Enums ( https://hibernate.atlassian.net/browse/HHH-16859?atlOrigin=eyJpIjoiNDU1Yz... )
Unfortunately, “I don’t see how it makes sense …” is not a valid argument in this discussion. I would like to provide some valid argumentation to consider in this topic:
* In any relational database there is an option to do:
SELECT max ( int ) FROM X
* Hibernate is the framework which has one job, this job is the O/R Mapping. That’s what the entity code I posted does:
@Column(name = "SOME_ENUM" )
@Enumerated(EnumType.ORDINAL)
private ESomeEnum type;
* The above proves the framework does not do what it is designed for. I would expect if the defined mapping is supported, everything that uses the O/R Mapping also should be supported. In this particular case if my int column is mapped to Enum, I should be able to work with the Enums in the code and those should also be properly mapped.
* Moreover, the functionalities around the Enums are inconsistent as, the above example is not possible, while the code below is:
@Query( "select s from SomeDbo s where enum = int " )
List<SomeDbo> findSomeOfTypeOne();
* This is also a regression to the previous versions where that functionality was supported.
* Last, but not least, if the Hibernate Team decided to not support it anymore, this should be documented and properly described in the Migration Guide, which currently is not the case.
( https://hibernate.atlassian.net/browse/HHH-16859#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16859#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:534ec1c )
2 years, 9 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=eyJpIjoiYzUzYTEzZGQz... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16860?atlOrigin=eyJpIjoiYzUzYT... ) HHH-16860 ( https://hibernate.atlassian.net/browse/HHH-16860?atlOrigin=eyJpIjoiYzUzYT... ) OneToMany with inherited classes on both sides ( https://hibernate.atlassian.net/browse/HHH-16860?atlOrigin=eyJpIjoiYzUzYT... )
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 to 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 )
2 years, 9 months