-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Narrowing problem
PostPosted: Fri Nov 14, 2008 10:49 am 
Beginner
Beginner

Joined: Mon Jan 31, 2005 11:04 am
Posts: 21
Dear all,

version hibernate 3.3.1

annotation config:
Code:
class Organization {
  @OneToMany
  private Set<Relation> relations;
}
class Person {
  @OneToMany
  private Set<Relation> relations;
}
@PrimaryKeyJoinColumn(name = "NotaryId")
class Notary extends Person {
}
class Relation {
  @ManyToOne
  private Person person;
  @ManyToOne
  private Organization organization;
}


I want to load the full Object Organization with its relations also loaded.

The problem is, for Relation having a Notary (sub class of Person) in their dependency I sometimes have the following WARN log:
10123 WARN org.hibernate.engine.StatefulPersistenceContext.ProxyWarnLog - Narrowing proxy to class be.fednot.bcn.domain.model.Notary - this operation breaks ==

What is strange is that it doesn't happen always, sometimes I get the Notary loaded. The SQL seems to load all the needed info.

This is a problem for me because I need to know if the Relation holds a Person or a Notary.

Any one knows how to fix this problem?

Bruno


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 28, 2009 2:21 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 2:42 pm
Posts: 77
Location: The Netherlands
Don't worry about his warning, just put the following in your log file and you shouldn't see it anymore:
Code:
   <!-- This overcomes the proxy narrow log of hibernate -->
   <logger name="org.hibernate.engine.StatefulPersistenceContext.ProxyWarnLog">
      <level value="error" />
   </logger>


Why it happens?
Suppose you have a Product with a many-to-one association to Address. Both are entities and Address has a ShippingAddress subclass.

Let's Session.get(..) a Product from the db that has ShippingAddress as association. Because the many-to-one is lazy, it will return a Address proxy. Note that this is a Address proxy and not a ShippingAddress proxy as the proxy will always match the type that is mentioned in Product (see the hibernate book for details).
This proxy is stored by Hibernate in his proxy cache.
Now we Session.get(...) the same ShippingAddress from the db, the one that is associated to the Product that we used fetched from the db.
Now Hibernate will see that it already contains a proxy for this ShippingAddress and will return this. However, it will notice that the types aren't the same so a "downcasting" must occur. Because this latter action isn't possible with "proxies" it will create new one and return it...

As you can see, nothing to worry about.
You could consider making the Address a value type...
In my case that's no option.

Hope this helps,
Ed Bras


Top
 Profile  
 
 Post subject: Re: Narrowing problem
PostPosted: Thu Nov 14, 2013 11:11 am 
Beginner
Beginner

Joined: Fri Nov 08, 2013 6:26 am
Posts: 21
Location: Germany
Hey there, I got a similar issue, but your solution does not work for me.

I got a class Ressource and a subclass SystemRessource.
Everything is working nice, but I got always a warning if I load some of my SystemRessource.

Code:
WARN 2013-11-14 16:07:31,790 [StatefulPersistenceContext] HHH000179: Narrowing proxy to class entity.SystemRessource - this operation breaks ==


I have made the following entry in my jboss standalone.xml

Code:
<logger category="org.hibernate.engine.StatefulPersistenceContext.ProxyWarnLog">
   <level name="WARN" />
</logger>


Any idea what I can do?

Regards
LStrike

Using JBoss AS 7.1.3 and hibernate 4.1.6.Final


Top
 Profile  
 
 Post subject: Re: Narrowing problem
PostPosted: Wed Jan 08, 2014 2:48 pm 
Newbie

Joined: Mon Jun 07, 2010 7:26 am
Posts: 5
@LStrike it seems that the ProxyWarnLog has gone away in Hibernate 4 (I'd be happy to be wrong on that!) which is a shame since Steve Ebersole added it for this:

https://hibernate.atlassian.net/browse/HHH-1367

The only way I've got this working is to use:

Code:
<logger category="org.hibernate.engine.internal.StatefulPersistenceContext">
    <level name="ERROR"/>
</logger>


Which is simply removing the ".ProxyWarnLog" (Edit and it adds in "internal" to the path)

(By the way - you need ERROR instead of WARN. It's logging at WARN level already so you need to go to the level above that).


Last edited by RedYeti on Thu Jan 09, 2014 10:08 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Narrowing problem
PostPosted: Thu Jan 09, 2014 4:11 am 
Beginner
Beginner

Joined: Fri Nov 08, 2013 6:26 am
Posts: 21
Location: Germany
@ RedYeti

Thank you very much, the message is gone from the log.


Top
 Profile  
 
 Post subject: Re: Narrowing problem
PostPosted: Thu Jan 09, 2014 10:07 am 
Newbie

Joined: Mon Jun 07, 2010 7:26 am
Posts: 5
@LStrike - no problem!

You might be interested in this posting I just made (assuming someone answers it with something useful that is!)

https://forum.hibernate.org/viewtopic.php?f=1&t=1030440


Top
 Profile  
 
 Post subject: Re: Narrowing problem
PostPosted: Thu Apr 24, 2014 5:02 pm 
Newbie

Joined: Thu Apr 10, 2014 3:07 pm
Posts: 1
@ RedYeti

I have added this to my log4j2.xml but because it's not able to override the jboss logging, the warning still shows up. Any idea how to suppress this?

<Logger name="org.hibernate.engine.internal.StatefulPersistenceContext" level="error" additivity="false">
<AppenderRef ref="ASYNC"/>
</Logger>

I am using hibernate 4.2.0.Final and jetty 9.0.5

WARN: HHH000179: Narrowing proxy to class ... - this operation breaks ==


Top
 Profile  
 
 Post subject: Re: Narrowing problem
PostPosted: Fri Apr 25, 2014 3:25 am 
Newbie

Joined: Mon Jun 07, 2010 7:26 am
Posts: 5
Sorry but without being able to change the JBosss logging I can't see how there's any way to suppress it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.