]
Julien Renaut commented on HHH-4235:
------------------------------------
I just ran into this bug at work.
A poor solution would be to change the entity to use a Set instead of a Map (since the Key
comes from the Value anyways) and build a transient Map when needed.
But i'd like to see this solved as it doesn't seem complicated.
One last comment: the snippet provided takes into account the possibility of a schema
being provided in the @Table annotation but a schema can also be provided through the use
of the "default_schema" configuration property. This must be checked too.
MapBinder.createFormulatedValue() does not honor DB schema name when
creating query
-----------------------------------------------------------------------------------
Key: HHH-4235
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4235
Project: Hibernate Core
Issue Type: Bug
Components: annotations
Environment: Hibernate 3.3.0.SP1, PostgresQL 8.3
Reporter: Sven Panko
I detected a problem with a ManyToMany mapping using a Map in the following setup:
@Entity
@Table(name = "entitya", schema = "myschema")
class EntityA {
...
@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@MapKey(name = "identifier")
@JoinTable(name = "entitya_entityb", schema="myschema", joinColumns
= @JoinColumn(name = "entitya_pk"), inverseJoinColumns = @JoinColumn(name =
"entityb_pk"))
@Cascade( { org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
private Map<String, EntityB> entityBMap = new HashMap<String, EntityB>();
}
@Entity
@Table(name = "entityb", schema = "myschema")
class EntityB {
...
}
The SQL generated to load the entityBMap collection contains a subquery in the select
clause, which looks like this:
select a8.identifier from entityb a8 where a8.pk=entityb0_.entityb_pk
(entityb0_.entityb_pk comes from the outer select clause)
The problem here is, that entityb in the from clause is not prepended by the schema name
"myschema" (the outer query is correctly doing this in the join clause,
however). I tracked this down to the createFormulatedValue() method in the MapBinder
class; the responsible code snippet is contained in lines 292 - 296:
StringBuilder fromAndWhereSb = new StringBuilder( " from " )
.append( associatedClass.getTable().getName() )
//.append(" as ") //Oracle doesn't support it in subqueries
.append( " " )
.append( alias ).append( " where " );
associatedClass.getTable().getName() does not return the fully qualified table name, so I
think this should look something like this:
StringBuilder fromAndWhereSb = new StringBuilder( " from " );
if (associatedClass.getTable().getSchema() != null) {
fromAndWhereSb.append(associatedClass.getTable().getSchema()).append('.');
}
fromAndWhereSb.append( associatedClass.getTable().getName() )
//.append(" as ") //Oracle doesn't support it in subqueries
.append( " " )
.append( alias ).append( " where " );
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: