Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Short answer is yes, you can change the discriminator value for the particular row(s) using <a href="http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/querysql.html" rel="nofollow noreferrer">native SQL</a>.</p> <p>However, I don't think NHibernate is intended to work this way, since the discriminator is generally "invisible" to the Java layer, where its value is supposed to be set initially according to the class of the persisted object and never changed.</p> <p>I recommend looking into a cleaner approach. From the standpoint of the object model, you're trying to convert a superclass object into one of its subclass types while not changing the identity of its persisted instance, and that's where the conflict is (the converted object isn't really supposed to be the same thing). Two alternative approaches are:</p> <ul> <li>Create a new instance of TierOneCustomer based on the information in the original Customer object, then delete the original object. If you were relying on the Customer's Primary Key for retrieval, you'll need to take note of the new PK.</li> </ul> <p>or</p> <ul> <li>Change your approach so the object type (discriminator) doesn't need to change. Instead of relying on a subclass to distinguish TierOneCustomer from Customer, you can use a property that you can modify freely at any time, i.e. Customer.Tier = 1.</li> </ul> <p>Here are some related discussions on the Hibernate Forums that may be of interest:</p> <ol> <li><a href="http://forum.hibernate.org/viewtopic.php?t=946531&amp;highlight=" rel="nofollow noreferrer">Can we update the discriminator column in Hibernate</a></li> <li><a href="http://forum.hibernate.org/viewtopic.php?p=2378169" rel="nofollow noreferrer">Table-per-Class Problem: Discriminator and Property</a></li> <li><a href="http://forums.hibernate.org/viewtopic.php?p=2291319&amp;sid=e61f05264d60d0ed3040ed7a76dbad73" rel="nofollow noreferrer">Converting a persisted instance into a subclass</a></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload