[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-4235) MapBinder.createFormulatedValue() does not honor DB schema name when creating query

João Francisco A. Enomoto (JIRA) noreply at atlassian.com
Fri Nov 19 09:09:13 EST 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4235?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=39172#action_39172 ] 

João Francisco A. Enomoto commented on HHH-4235:
------------------------------------------------

Just found this bug as well here at work and would like to see it solved. Does anyone know when it'll be solved?

> 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: 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