-->
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: Can't use CacheAttribute on classes
PostPosted: Sun May 14, 2006 3:55 pm 
Newbie

Joined: Sun May 14, 2006 3:49 pm
Posts: 5
Using NHibernate.Mapping.Attributes, I can't use the CacheAttribute on a class -- I get this error from the compiler:

Code:
Attribute 'Cache' is not valid on this declaration type. It is valid on 'property, indexer, field' declarations only.


Is there any specific reason for this? Judging by the docs at http://www.hibernate.org/hib_docs/nhibernate/html/performance.html#performance-cache, it should be available on classes as well.

The application I'm working on is ASP.NET 2.0, using NHibernate version 1.2.0, and the declaration of the class I'm trying to cache is:

Code:
[Class(0, Table = "`sample`")]
[Cache(1, Usage = CacheUsage.ReadWrite)]
public partial class @Sample


Top
 Profile  
 
 Post subject: More trouble
PostPosted: Sun May 14, 2006 4:18 pm 
Newbie

Joined: Sun May 14, 2006 3:49 pm
Posts: 5
I tried to recompile the NHibernate.Mapping.Attributes project and add the System.AttributeTargets.Class target to CacheAttribute. Even using this newly compiled version, I get no <cache> or <jcs-cache> directly underneath <class> elements, using the default HbmSerializer.

I checked the nhibernate-mapping-2.0.xsd file, and as far as I can tell, it allows <cache> as children of the <class> element, so I'm totally lost on the cause of this.

Can anybody help?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 15, 2006 7:03 am 
Newbie

Joined: Sun May 14, 2006 3:49 pm
Posts: 5
Anybody?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 15, 2006 7:29 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
I forwarded this topic to Pierre Henri Kuaté, the NHMA maintainer, so he should reply in a few days.

From what I know, NHMA is entirely automatically generated from the XSD schema, and attributes corresponding to elements nested inside of <class> element are generated with usage = property/field. I don't know if anything can be done about it, so please wait for Pierre Henri to reply.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 15, 2006 9:31 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
As Sergey said, attributes corresponding to elements nested inside of <class> element must be applied to property/field (even if it doesn't really make sense as it is the case for CacheAttribute).

The right code is:
Code:
[Class(Table = "`sample`")]
public partial class @Sample
{
    [Cache(Usage = CacheUsage.ReadWrite)]
    private Type someField/Property;
}

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 9:05 am 
Newbie

Joined: Sun May 14, 2006 3:49 pm
Posts: 5
Does that mean the first field/property of the class, or will any field do the job?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 1:20 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
"Any field/property do the job" :) (just make sure that it is the only NHMA attribute on it or that you put it first)

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 5:31 am 
Newbie

Joined: Sun May 14, 2006 3:49 pm
Posts: 5
Thank you very much! You saved my day.


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.