package com.peterphi.std.guice.hibernate.webquery.discriminatortest;

import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING)
abstract class MyBaseObject
{
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long id;


	@Override
	public String toString()
	{
		return getClass().getSimpleName() + "{" +
		       "id=" + id +
		       '}';
	}
}

package com.peterphi.std.guice.hibernate.webquery.discriminatortest;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
// DiscriminatorColum has been commented out to work around a bug in Hibernate - see https://hibernate.atlassian.net/browse/HHH-9501
// A Discriminator is not required for this functionality in our library, but I've left this reference here to make it easier to figure
// Out what's going wrong in the future
//@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING)
abstract class MyBaseObject
{
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long id;


	@Override
	public String toString()
	{
		return getClass().getSimpleName() + "{" +
		       "id=" + id +
		       '}';
	}
}

Work around Hibernate bug https://hibernate.atlassian.net/browse/HHH-9501 where a DiscriminatorColum and DiscriminatorValue being used results in invalid SQL being generated for SELECT queries that specify a particular subclass (appears to impact HSQLDB dialect in Hibernate 4.2.x and 4.3.x)