[hibernate-issues] [Hibernate-JIRA] Commented: (ANN-562) CLONE -Discriminator column not supported with JOINED strategy: another reason

Amit Kasher (JIRA) noreply at atlassian.com
Sat Feb 24 09:06:31 EST 2007


    [ http://opensource.atlassian.com/projects/hibernate/browse/ANN-562?page=comments#action_26281 ] 

Amit Kasher commented on ANN-562:
---------------------------------

I don't understand why this should be worked around instead of just supported (honoring the discriminator column annotation)? Using a SINGLE_TABLE has many disadvantages (denormalization, NOT_NULLs not possible, etc).
It can have a low priority, but rejecting it completely...? Isn't it a bit extreme?

I worked around this issue by creating a manual discriminator column, and initializing it differently in the subclasses' constructors. For example:

@Entity public class A {
...
	@NotNull protected final String discriminator;

	public A(String discriminator, String name) {
		this.discriminator = discriminator;
		this.name = name;
	}
...
}

@Entity public class B extends A {
...
	public B(String name, int height) {
		super(B.class.getSimpleName(), name);
		this.height = height;
	}
...
}

@Entity public class C extends A {
...
	public C(String name, int width) {
		super(C.class.getSimpleName(), name);
		this.width = width;
	}
...
}

> CLONE -Discriminator column not supported with JOINED strategy: another reason
> ------------------------------------------------------------------------------
>
>          Key: ANN-562
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-562
>      Project: Hibernate Annotations
>         Type: Bug

>     Versions: 3.1beta6
>  Environment: Hibernate 3.1rc2, Hibernate Annotations 3.1b6
>     Reporter: Amit Kasher

>
>
> Section 9.1.27 of the EJB3 persistence public draft says, "The DiscriminatorColumn annotation is used to define the discriminator column for SINGLE_TABLE and JOINED mapping strategies." But Hibernate ignores the DiscriminatorColumn annotation when the mapping strategy is JOINED; when a JOINED entity is persisted, its discriminator column is not included in the SQL "insert" statement, resulting in a not-null constraint violation if the discriminator column is marked NOT NULL in the database.
> The JOINED strategy with discriminators is pretty ubiquitous in EJB3 sample code and tutorials out on the net, so lots of people are likely to run into this as they try out EJB3 for the first time. A few examples:
> http://www.oracle.com/technology/tech/java/oc4j/ejb3/howtos-ejb3/howtoejb30inheritance/doc/how-to-ejb30-inheritance.html
> http://www.solarmetric.com/Software/Documentation/4.0.0EA/docs/full/html/ejb3_overview_mapping_discrim.html
> http://www.caucho.com/resin-3.0/amber/tutorial/cmp-inherit/index.xtp

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list