Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: @AttributeOverride doesn't work with TABLE_PER_CLASS
PostPosted: Wed Oct 25, 2017 7:55 am 
Newbie

Joined: Wed Oct 25, 2017 7:42 am
Posts: 3
Hello folks,
I am trying to do an attribute override, but it does not seem to work. Let me show my case.

I have a basic device entity such as this one:

Code:
@MappedSuperclass
public abstract class BasicDeviceData{

    @Id
    @GeneratedValue
    private Long id;

    @Column(nullable = false, unique = true)
    private String uuid;

    @Column(nullable = false)
    private String name;

    @Column(nullable = false)
    private String state;
...


For each one of the devices I have entities such as:
Code:
@Entity
@Table
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class DeviceTypeX extends BasicDeviceData {

    @Column(nullable = false)
    private Long regionId;
.... much more data...



Then, for each deviceType, I have a history table that has all device information with a timestamp:
Code:
@Entity
@Table
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@AttributeOverride(name = "uuid", column = @Column(unique = false))
public class DeviceTypeXHistory extends DeviceTypeX {

    @Column(nullable = false)
    private Date timeStamp;



My problem is that I cannot have a unique constraint in "DeviceTypeXHistory" history. I tried using "@AttributeOverride" to remove that constraint, but it is not working. Is there any way to remove/override that constraint declaration that I am getting by inheritance in DeviceTypeXHistory table?

I am using the following:
Hibernate version: 5.2.12.Final
Spring-data-jpa: 1.11.8.RELEASE
Java: jdk1.8.0_66


Top
 Profile  
 
 Post subject: Re: @AttributeOverride does not seem to work
PostPosted: Wed Oct 25, 2017 10:08 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1525
According to JPA specs, @AttributeOverride can only be used when you want to override a property from a @MappedSuperclass, not for materialized entity inheritance.

By the way, the usage of TABLE_PER_CLASS is problematic because it's not very efficient. You are better off using SINGLE_TABLE or JOINED instead.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: @AttributeOverride does not seem to work
PostPosted: Wed Oct 25, 2017 11:59 am 
Newbie

Joined: Wed Oct 25, 2017 7:42 am
Posts: 3
[UPDATE] I tested with eclipselink version 2.6.4 and everything is working now.
I do not know if my use case is accepted by JPA specification, but at least it works with some JPA implementation.

I will wait on people's feedback here, and if it is a bug I can open a Jira ticket.


Top
 Profile  
 
 Post subject: Re: @AttributeOverride does not seem to work
PostPosted: Wed Oct 25, 2017 12:00 pm 
Newbie

Joined: Wed Oct 25, 2017 7:42 am
Posts: 3
Thanks for the feedback Vlad.
Well, what do you mean by efficiency losses when you talk about "TABLE_PER_CLASS"? Are you referring to storage space?


Top
 Profile  
 
 Post subject: Re: @AttributeOverride does not seem to work
PostPosted: Wed Oct 25, 2017 12:59 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1525
The queries are extremely inefficient for TABLE_PER_CLASS. I don't have an example on my blog for that, I only have it covered in my book High-Performance Java Persistence.

As for that feature, we have the HHH-2619 issue. Most likely, it will only be considered after we release Hibernate 6.

If you want to implement it, send me a Pull Request and I'll make sure to review it and integrate. Otherwise, we'll take care of other more issues with a higher priority.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.