Issue Details (XML | Word | Printable)

Key: HHH-4244
Type: Bug Bug
Status: Open Open
Priority: Minor Minor
Assignee: Paolo "Nusco" Perrotta
Reporter: Sebastian Kirsch
Votes: 3
Watchers: 3
Operations

If you were logged in you would be able to see more operations.
Hibernate Core

Type aproximation and unbound type limitation

Created: 11/Jan/07 05:28 AM   Updated: 10/Sep/09 01:34 PM
Return to search
Component/s: annotations
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive Hibernate ANN-526.zip (4 kB)
2. Zip Archive Hibernate-ANN-526_SecondCase.zip (4 kB)
3. Zip Archive Hibernate-ANN-526_SecondCase.zip (5 kB)

Issue Links:
Relates
 

Bug Testcase Reminder (view):
REMINDER: Bug reports should generally be accompanied by a test case
Participants: Emmanuel Bernard, Paolo "Nusco" Perrotta and Sebastian Kirsch


 Description  « Hide

I get this "Property reference has an unbound type and no explictit target entity" exception and I think this is not exactly true. I'm not sure if this is a bug or a feature requests though.

Have a look at the attached files and read on.

I guess the model ist pretty easy to understand. The AbstractGeneric allows my to have concrete entities referring to specifc other subclasses - as seen in ConcreteOther and ConcreteSelf. The test case "workingClasses" shows us that Hibernate may work with this model - note that the class AbstractGeneric itslef was NOT added to the configuration.

Now for the problem: The class OtherEntity is a completly different entity, but it refers to instances of AbstractGeneric - to any subclass of it actually, as AbstractGeneric is obviously abstract.
If you run the test case "otherClass" the first part states that Hibernate doesn't know AbstractGeneric - which is fine, so I add that class to the configuration and try to build a session factory again. Now we receive the beforementioned exception.

That's the situation. So is AbstractGeneric really an unbound type? I'd say it is not - T has an upper bound which should be good enough to work with - we know the table and the PK...



Sebastian Kirsch added a comment - 11/Jan/07 05:29 AM

The Model and JUnit


Emmanuel Bernard added a comment - 16/Jan/07 05:02 PM

my understanding is that
T in AbstractGenerics is not resolved in your system.
Because T is a subtype of AbstractGenerics<U>, U not being resolved.
Am I wrong?


Emmanuel Bernard added a comment - 16/Jan/07 05:02 PM

WDYT?


Sebastian Kirsch added a comment - 17/Jan/07 02:30 AM

T in AbstractGenerics is not resolved - this is correct.
But T has an upper bound: it must be a subclass of AbstractGenerics.
As I mentioned before, I'm not sure if this is sufficient data to build up the model, but I hope it could be arranged to be enough.
So it may not be a bug but a feature request...


Paolo "Nusco" Perrotta added a comment - 17/Jan/07 02:39 AM

In general, upper bounds should be recognized (except for some special cases, such as multiple upper bounds, where we just give up and approximate the type to Object). I'll look into this.


Emmanuel Bernard added a comment - 17/Jan/07 08:19 AM

this case is an infinite multiple upper bound case, if you compute at the infinite limit you should find the type


Paolo "Nusco" Perrotta added a comment - 18/Jan/07 04:12 AM

It's a broader problem than I thought. I'm still not 100% sure that fixing it will change the behaviour described by Sebastian, but I found other cases that are more clearly pathological. For example, this is not approximated correctly, even if in theory it should:

class SomeGenericType<T extends SomeType> {
public T property() {return null;}
}

We don't even have recursive definitions here, but HA still doesn't notice that the property type can be approximated to a SomeType. The problem is that I focused on resolving generic types in hierarchies - but there are cases (like the one above) where you can make a decent approximation of types by just looking at the class itself. It's not really a bug, as this is on the border of what people should be expecting to do - but as a feature request, it's very reasonable. What do you think, Emmanuel?

We have many corner cases where type binding doesn't work as well as Java's - generics in interfaces, inner classes and so on. Java makes extremely difficult to work reflexively at this level. This one probably deserves fixing, though.


Paolo "Nusco" Perrotta added a comment - 21/Jan/07 11:43 AM

After some thought, this is a slippery slope. If we accept this:

class SomeGenericType<T extends SomeType> {
public T property() {return null;}
}

Then there is no reason why we shouldn't accept this implicit upper bound as well:

class SomeOtherGenericType<T> {
public T property() {return null;} // T is approximated to Object
}

The problem is how much we want to push this type of guessing. I see four options:

1 - The system tries to be smart and approximates all generic types as well as it can. List<T extends Runnable> becomes List<Runnable>, T becomes Object and so on. This might cause problems at runtime, of course.
2 - The system does as above, but logs a warning every time an approximated type is registered.
3 - The system approximates only in certain situations. Maybe different approximation strategies can be plugged in.
4 - The system doesn't try to be too smart, and throws an error whenever a type is not fully resolved.

Emmanuel, WDYT?


Emmanuel Bernard added a comment - 23/Jan/07 03:35 PM

1 - The system tries to be smart and approximates all generic types as well as it can. List<T extends Runnable> becomes List<Runnable>, T becomes Object and so on. This might cause problems at runtime, of course.

> I'm OK for everything but Object, if you declare an upper bound, you tend to know what you are doing. However, for Object people would be too surprised, esp the one not understqnding generics ( like me )

2 - The system does as above, but logs a warning every time an approximated type is registered.

-1, we had that but the user experience was bad for Hibernate Validator

3 - The system approximates only in certain situations. Maybe different approximation strategies can be plugged in.

An approximation strategy might be interesting, we sort of have that through the boolean rendering true/false depending on whether approximation was used or not

4 - The system doesn't try to be too smart, and throws an error whenever a type is not fully resolved.

-1 there are usecases that require approximation


Sebastian Kirsch added a comment - 24/Jan/07 05:17 PM

Hi Paolo!

I stumbled upon another issue - see second zip file.

I'm not sure if it has the same cause like the other stuff, but it is at least related. Please check the provided TestCase...


Paolo "Nusco" Perrotta added a comment - 24/Jan/07 05:37 PM

To Sebastian: whoops, I think you posted the .class files instead of the source.


Sebastian Kirsch added a comment - 25/Jan/07 02:07 AM

Should have made me wonder when I had to rename the .jar to .zip...