-->
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.  [ 1 post ] 
Author Message
 Post subject: Restricting inserts on discriminator using JPA annotations
PostPosted: Wed May 25, 2011 9:21 am 
Newbie

Joined: Wed May 25, 2011 8:55 am
Posts: 1
I'm in the process of migrating a very large library from Hibernate 2.1 to Hibernate 3.5.

I have a few entities that map using the single table strategy and map to views within an Oracle DB.

In the 2.1 mapping file, I'm able to restrict insert on the discriminator value like so:

<discriminator column="FOO" type="string" insert="false" />

It doesn't appear that I'm able to use this same approach using JPA annotations.

My base class looks a bit like this:

@Entity
@Table(name="V_BAR")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="FOO")

public class Bar { ...

and my subclasses look a bit like this:

@Entity
@DiscriminatorValue("S")

public class SaladBar extends Bar{...

Can anyone describe a good approach to restricting inserts on the discriminator column?

The workaround I have implemented has been replacing @DiscriminatorColumn with @DiscriminatorFormula on the base class,
so that the base class looks a bit like this:

@Entity
@Table(name="V_BAR")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorFormula (value="FOO")

public class Bar { ...

This seems to do the trick for now, but doesn't seem like the "proper" approach (and being a bit of a Hibernate / ORM newbie, I still need to do a bit of research into the whys and hows)

Thanks!
++dave;


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.