[Hibernate-JIRA] Created: (HHH-2872) MappingException thrown for @ManyToOne join if table on the left of the association is alphabetically lower than table on the right
by Mukesh (JIRA)
MappingException thrown for @ManyToOne join if table on the left of the association is alphabetically lower than table on the right
-------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-2872
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2872
Project: Hibernate3
Issue Type: Bug
Components: core, query-hql
Affects Versions: 3.2.5
Reporter: Mukesh
I get a MappingException for @ManyToOne join if table on the left of the association is alphabetically lower than table on the right
I have tables VO_USER, V_ORGANIZATIONAL and VO_AREA
VO_USER has USR_IDR as primary key.
V_ORGANIZATIONAL has a composite primary key of BUSINESS_AREA_CODE and CODE
VO_AREA has BUS_ARA_IDR as the primary key
I get the following exception when I join the VO_USER table with the V_ORGANIZATIONAL table
"org.hibernate.MappingException: Unable to find column with logical name: BUSINESS_AREA_CODE in org.hibernate.mapping.Table(V_ORGANIZATIONAL_GRADE) and its related supertables and secondary tables"
Howerver, if I rename the table V_ORGANIZATIONAL to VO_ORGANIZATIONAL, it works fine - which makes me conclude that it is an issue with the alphabetical ordering of the tables in the association. The table name on the left side of the @ManyToOne join must be alphabetically greater than the table on the right side - perhaps of the way hibernate loads the classes ??
Can someone confirm that is the issue, and what is the workaround/solution as I dont want to change the name of the table
The simplified Code :
@Entity
@org.hibernate.annotations.Entity(mutable = true)
@Table(name = "VO_USER")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "user")
public class User implements Serializable
{
private static final long serialVersionUID = -1894472442328538017L;
@Id
@Column(name = "USR_IDR")
private String userId;
@ManyToOne
@JoinColumn(name = "BUS_ARA_IDR", insertable = false, updatable = false, unique = false, nullable = false)
private BusinessArea businessArea;
@ManyToOne(targetEntity = Organizational.class)
@JoinColumns( {
@JoinColumn(name = "BUS_ARA_IDR", referencedColumnName = "BUSINESS_AREA_CODE", unique = false, insertable = false, updatable = false, nullable=true),
@JoinColumn(name = "USR_GRD", referencedColumnName = "CODE", unique = false, insertable = false, updatable = false, nullable=true)
})
private Organizational organizational;
....
}
@Entity
@Table(name = "V_ORGANIZATIONAL")
@IdClass(OrganizationalKey.class)
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = "organization")
public class Organizational implements CodedValue,
Comparable<Organizational>, Serializable
{
private static final long serialVersionUID = 7414956278287853961L;
@Id
private String code;
@Id
private BusinessArea businessArea;
private Organizational()
{
}
....
}
public class OrganizationalKey implements Serializable
{
private static final long serialVersionUID = -8022957102173252455L;
@ManyToOne(targetEntity = BusinessArea.class)
@JoinColumn(name = "BUSINESS_AREA_CODE", insertable = false, updatable = false)
private BusinessArea businessArea;
@Column(name = "CODE", length = 5, insertable = false, updatable = false)
private String code;
OrganizationalKey()
{
}
....
}
@Entity
@Table(name = "VO_AREA")
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = "organization")
public class BusinessArea implements CodedValue, Serializable
{
private static final long serialVersionUID = 6911068689852530787L;
@Id
@Column(name = "BUS_ARA_IDR", length = 3, updatable = false)
private String code;
private BusinessArea()
{
};
}
--
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....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
17 years, 3 months
[Hibernate-JIRA] Commented: (HHH-530) Better handling of filter params in HQL to allow filter use on subqueries
by Shawn Clowater (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-530?page=co... ]
Shawn Clowater commented on HHH-530:
------------------------------------
Well, I took a look at this original patch and of course the state of the world changed quite a bit since 3.0.5. However, I think I have something that will work that is much less complex than the original patch. The issue seems to be that once the process filters are done that you can't determine the order of the filters to positional values.
But, it looks like all the information is available as the filters are being processed to add both the filters and positional params in the correct order. Essentially the patch is processing the filters in the same manner as it was before but for the positional piece it will add the parameters based on the ordinal value from the positionalValues/Types array as it encounters them.
The only changes to QueryParameters are really
else {
if (token.equals( "?" ) && positionalIndex < getPositionalParameterValues().length) {
parameters.add( getPositionalParameterValues()[positionalIndex] );
parameterTypes.add( getPositionalParameterTypes()[positionalIndex] );
positionalIndex++;
}
result.append( token );
}
removal of the
parameters.addAll( Arrays.asList( getPositionalParameterValues() ) );
parameterTypes.addAll( Arrays.asList( getPositionalParameterTypes() ) );
and the defining of the positionalIndex int variable. For some reason my IDE wanted to reformat the white space.
The first concern I had was what happened if someone mixed and matched positional and named parameters but it would seem the parser disallows that. I don't see any drawback to shuffling the parameters into the right order if all that is being done on the other side is mowing through them in order.
Note that this also assumes that the enabled filters are being passed through to the subquery. That is disabled in the latest version of the code.
> Better handling of filter params in HQL to allow filter use on subqueries
> -------------------------------------------------------------------------
>
> Key: HHH-530
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-530
> Project: Hibernate3
> Issue Type: Bug
> Components: core
> Reporter: Gavin King
> Assignee: Steve Ebersole
> Attachments: hibernate_filter_fix-3.0.5.patch, hibernate_filter_fix-3.0.5_14.patch
>
>
> Currently filter conditions are applied in subselects, they should not be.
--
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....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
17 years, 3 months