[hibernate-issues] [Hibernate-JIRA] Created: (HHH-4597) Unhelpful error message with property-ref to non-existent property

Chris Wilson (JIRA) noreply at atlassian.com
Sun Nov 22 08:54:08 EST 2009


Unhelpful error message with property-ref to non-existent property
------------------------------------------------------------------

                 Key: HHH-4597
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4597
             Project: Hibernate Core
          Issue Type: Bug
          Components: core
    Affects Versions: 3.3.2
         Environment: Hibernate 3.3.2 GA, annotations, MySQL 5.0.51a-3ubuntu5.4
            Reporter: Chris Wilson
         Attachments: HibernatePropertyRefNotFoundErrorMessageTest.java

When a mapping references a property in another mapping that doesn't exist, Hibernate gives an exception like this:

  org.hibernate.MappingException: property-ref [projectSite] not found on entity [org.wfp.rita.dao.ProjectSite]

which doesn't give the most important information: where the reference came *from*. Without this, you have to hunt through all your mapping files looking for a property-ref to the table and property that doesn't exist.

Might I suggest an error message like this instead?

Association property [owner] of [org.wfp.rita.datafacade.HibernatePropertyRefNotFoundErrorMessageTest$House]
references unknown property [ssn] of [org.wfp.rita.datafacade.HibernatePropertyRefNotFoundErrorMessageTest$Person].

The attached test case reproduces the issue and tests for the new error message, please adjust to taste.

I know this is not a show-stopper but it's a major irritation and waste of time to have to figure out what this exception means and dig through all your mappings to find the problem.

Sorry I didn't create a patch, but Hibernate is not exactly simple to build. Unfortunately the referencing property (association) name is not immediately accessible during the second pass where this error is thrown, but I think it could be fixed using something like this:

ManyToOne.java:

public void createPropertyRefConstraints(Map persistentClasses) {
	if (referencedPropertyName!=null) {
		PersistentClass associationClass = (PersistentClass) persistentClasses.get(getAssociatedEntityName() );
		String associationPropName;
		for (Property prop : associationClass.getProperties())
		{
			if (prop.getValue() == this)
			{
				associationPropName = prop.getName();
				break;
			}
		}

		if (associationPropName == null) throw Exception(...)

		PersistentClass pc = (PersistentClass) persistentClasses.get(getReferencedEntityName() );
		
		try
		{
			Property property = pc.getReferencedProperty( getReferencedPropertyName() );
		}
		catch (MappingException e)
		{
			throw new MappingException("Association property [" +
				associationPropName + "] of [" +
				getAssociatedEntityName() + "] references unknown property [" +
				getReferencedPropertyName() + "] of [" +
				getReferencedEntityName() + "]", e);
		}

Cheers, Chris.

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