-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Support for @DiscriminatorValue "null" and "not null"
PostPosted: Tue May 10, 2016 7:54 am 
Newbie

Joined: Tue May 10, 2016 7:27 am
Posts: 3
Hi,
I discovered the keywords "null" and "not null" for the @DiscriminatorValue annotation value and it seems to match my need. (To have a default Entity class in my inheritance strategy.
However, before considering using this feature in my application and deploy it in production environment, I would like to find some documentation about it.
I don't want to use a "hidden feature" which could be removed in a newer version.

Is there some (official?) documentation on this feature?
The only reference I found was:
Quote:
discriminator-value (optional - defaults to the class name): a value that distinguishes individual subclasses that is used for polymorphic behavior. Acceptable values include null and not null.

(from https://docs.jboss.org/hibernate/orm/4. ... tion-class)

Sorry for my poor english...


Top
 Profile  
 
 Post subject: Re: Discriminator value "null"/"not null"
PostPosted: Mon May 16, 2016 8:47 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
This class is defined by JPA so it is supported and it will not be removed. The JPA spec and the Javadocs are also authoritative resources.

You can use the @DiscriminatorValu to distinguish between subclasses that belong to the same inheritance tree. If the value is null, then Hibernate will use an implicit naming strategy. If you provide a non-null value explicitly, Hibernate is going to use that value for identifying the subtype.


Top
 Profile  
 
 Post subject: Re: Support for @DiscriminatorValue "null" and "not null"
PostPosted: Wed Jun 01, 2016 2:12 am 
Newbie

Joined: Tue May 10, 2016 7:27 am
Posts: 3
I consider using the "not null" String value, not a not-null value.
Code:
@DiscriminatorValue("not null")

"null" and "not null" seem to be reserved values.

If I have the following entities:
Code:
@DiscriminatorValue("DOG")
class DogEntity {...}

@DiscriminatorValue("not null")
class DefaultAnimalEntity {...}


Then if value is "DOG", as expected, Hibernate returns a DogEntity.
But if value is "CAT", "BIRD" or anything other than "DOG", Hibernate returns a DefaultAnimalEntity.
That is the behavior I want, but I found nothing in any documentation, except the line I quoted in the first message.

I found these two values hard-coded in Hibernate PersistentClass source http://grepcode.com/file/repo1.maven.org/maven2/org.hibernate/hibernate-core/4.2.0.Final/org/hibernate/mapping/PersistentClass.java/#55.
They are then used here: http://grepcode.com/file/repo1.maven.org/maven2/org.hibernate/hibernate-core/4.2.0.Final/org/hibernate/mapping/PersistentClass.java/#493
But I don't know if it is a standard behavior and if I can rely on it.


Top
 Profile  
 
 Post subject: Re: Support for @DiscriminatorValue "null" and "not null"
PostPosted: Wed Jun 01, 2016 4:23 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I'm going to ask on the mailing list to see if this is official and we need to document it.


Top
 Profile  
 
 Post subject: Re: Support for @DiscriminatorValue "null" and "not null"
PostPosted: Mon Jul 18, 2016 6:37 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I have just documented the NULL and NOT NULL options. I also wrote a blog post about it.

However, there are other options as well.

You can use @DiscriminatorOptions as documented in the User Guide.


Top
 Profile  
 
 Post subject: Re: Support for @DiscriminatorValue "null" and "not null"
PostPosted: Wed Oct 05, 2016 9:21 am 
Newbie

Joined: Tue May 10, 2016 7:27 am
Posts: 3
Great!

Thanks a lot!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.