[
https://jira.jboss.org/jira/browse/EJBTHREE-487?page=com.atlassian.jira.p...
]
Jan Vorwerk commented on EJBTHREE-487:
--------------------------------------
Just for the record because this bug scores a good rank in Google searches...
The issue seems to be that the example above misses the @Where clause:
@OneToMany(mapedBy="master)
@Where(clause="TYPE=1")
List<Type1> getType1s()
@OneToMany(mapedBy="master)
@Where(clause="TYPE=2")
List<Type2> getType2s()
Hope this helps.
relation to a subclass doesn't limit query whit type
----------------------------------------------------
Key: EJBTHREE-487
URL:
https://jira.jboss.org/jira/browse/EJBTHREE-487
Project: EJB 3.0
Issue Type: Bug
Affects Versions: EJB 3.0 RC5 - PFD
Environment: JBoss 4.0.4 RC1
not db specific
Reporter: Jernej Srebrni?
Assignee: Emmanuel Bernard
Priority: Critical
Attachments: bugClassDiagram.png, BugEntityDiagram.png
DB Entiy:
table Master (...)
table Detail(
FK master,
type
)
Classes:
@entity
@table(name="Deatail")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType =
DiscriminatorType.INTEGER)
@DiscriminatorValue(value = "0")
abstract class AbstracDetail ...{..
@ManyToOne
Master getMaster()
..}
@entity
@DiscriminatorValue(value = "1")
abstract class Type1 ...{....}
@entity
@DiscriminatorValue(value = "2")
abstract class Type2 ...{....}
@entity
class Master{...
@OneToMany(mapedBy="master)
List<Type1> getType1s()
@OneToMany(mapedBy="master)
List<Type2> getType2s()
...}
Code some where:
master.getType1s()...
JBoss generated select, whit out type limiting:
select ... from Detail where master=?master?
Right select:
select ... from Detail where master=?master? and type=1
whit code :
entityManager.createQuery(" from Type1 t where t.master=:master ").......
the right select is generated.
CRITICAL sitiation:
insert Type1 and Type2 data for the same master.
master.getType1s() or master.getType2s() will fail beacuse hibernate will try to create
type1 with type2 data (and vice versa)
if relation is set onoToone type cheching is added to the select
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira