I have a table defnition as given below:
License
ClientId
Type
Total
Used
ClientId and Type together uniquely identifies a row. I have a mapping file as given below:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="Acumen.AAM.Domain.Model.License, Acumen.AAM.Domain" lazy="false" table="License">
<id name="ClientId" access="field" column="ClientID" />
<property name="Total" access="field" column="Total"/>
<property name="Used" access="field" column="Used"/>
<property name="Type" access="field" column="Type"/>
</class>
</hibernate-mapping>
If a client used a license to create a user, I need to update the Used column in the table. As I set ClientId column as the id column for this table in the mapping xml, I am getting TooManyRowsAffectedException.
could you please let me know how to set a composite key at mapping level so that NHibernate can udpate based on ClientId and Type.
Something like: Update License SET Used=Used-1 WHERE ClientId='xxx' AND Type=1
Please help.
Thanks,
Mahesh
You have to use a composite-id
http://nhibernate.info/doc/nh/en/index.html#mapping-declaration-compositeid
If you primary key is composite, your mapping should reflect that, and your class needs to override Equals and GetHashCode.
Also, if ClientId is the primary key of your Client entity, you should map it as many-to-many, not just an Id.
Also, why are you specifying lazy="false"? Are you aware of the implications?
Also, why map everything with access="field"? Do the properties have some special logic?
This is a revised mapping considering everything I just wrote. Feel free to ignore those parts that don't apply :-)
<class name="Acumen.AAM.Domain.Model.License, Acumen.AAM.Domain" table="License">
<composite-id>
<key-many-to-one name="Client" column="ClientID" />
<key-property name="Type" />
</composite-id>
<property name="Total" />
<property name="Used" />
</class>
As the other comrades mentioned above, you have to use a composite-id, which is not a best but acceptable practice.
On the other hand, you can simply write an update interceptor and make sure your Type = 1 within it.
Here are some link about the topic to help you see clear in this.
Elegant code : Implementing NHibernate Interceptors
NHibernate Documentation : Interceptors
Sample NHibernate IInterceptor implementation
Enterprise .NET Community : NHibernate Part 2 (Scroll down to : Interceptors and Persistent Lifecycle)
NHibernate Interceptor Auditing Inserted Object Id (SO question)
The main advantage of using interceptors over a composite key is that it doesn't break your DBRM and provides a definitely more flexible solution, without "polluting" your mapping file which will more precisely represent your model.
Related
I'm using the message-properties component in mule. I need to set a dynamic key name as this is used to add custom headers to a http-request.
<message-properties-transformer doc:name="Message Properties" scope="session">
<add-message-property key="#[flowVars.name]" value="#[payload.split(":")[1]]"/>
</message-properties-transformer>
When logging the output, it shows that the key has not evaluated the MEL expression contained inside:
SESSION scoped properties: #[flowVars.name]=Basic pokpogytg788t878
Is there any way of setting a dynamic key name for a property in this component?
I have faced similar situation,where I had to set dynamic message properties.
I tried several things to set it with message-properties-transformer , but to no luck.
There is some bug filed for similar issue,below is the link
Cannot use MEL expression as key in Message Properties transformer
After trying for sometime I got that working with some workaround.
You can try working it around with Expression component.
<expression-component doc:name="Expression">
<![CDATA[message.outboundProperties[flowVars.name]=payload.split(':')1];]]>
</expression-component>
Not only you can read dynamic values from payload/variables.But you can also call your custom java/groovy methods in it.
Try below code snippet,and let us know if that works for you.
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration"
path="/test" doc:name="HTTP" allowedMethods="POST" />
<set-variable variableName="name" value="#["test"]"
doc:name="name" />
<expression-component doc:name="Expression">
<![CDATA[message.outboundProperties[flowVars.name]=payload.split(':')1];]]>
</expression-component>
</flow>
This is the definition of a dexterity content type in Plone:
<schema>
<field name="categories" type="zope.schema.List">
<description>Each line one category</description>
<required>True</required>
<title>Categories</title>
<default>[u'General', ]</default>
<value_type type="zope.schema.TextLine"></value_type>
<missing_value>()</missing_value>
</field>
</schema>
How does the default value has to be declared? I would expect that a list has to be provided in this way above. But this is not working. Any suggestions?
You are not supposed to provide a manually serialized list, just create a list of XML elements. Use the following format:
<default>
<element>General</element>
<element>Specific</element>
</default>
Hint: the easiest way to find the right format is to use the Dexterity inline schema editor, so you can set your default value in the UI, and then you just need to switch to "Edit XML Field model" to get the resulting XML source.
There are several answered questions detailing how to refer to a single value from web.config file. I'd like to maintain lists of values with which to populate combo boxes in the Views. Should I use some sort of key/value pair structure, with the key identifying the particular combo box to populate?
<add key="CalculationMethod" value="Fixed"/>
<add key="CalculationMethod" value="Cost Plus"/>
<add key="CalculationMethod" value="Formula"/>
I'm not sure how I'd read this, or if that would even work (don't keys have to be unique?). The IntelliSense for web.config doesn't seem to allow much in the appSettings section that looks applicable to a more robust structure like
<list name="CalculationMethod">
<item value="Fixed"/>
<item value="Cost Plus"/>
<item value="Formula"/>
</list>
I see that the root <configuration> has a lot of options for children, but which one to use, if any?
You really should be using a database for something like this but if you must put it in the web.config then you could delimit the values and parse them out at run time.
<add key="CalculationMethod" value="Fixed,Cost Plus,Formula"/>
myComboBox.DataSource = new List<String>(lstrCalcMethodsFromWebConfig.Split(','));
The data dictionary pretty much forces every node in Alfresco to have a sys:locale value:
<type name="sys:base">
<title>Base</title>
<mandatory-aspects>
<aspect>sys:referenceable</aspect>
<aspect>sys:localized</aspect>
</mandatory-aspects>
</type>
<!--
Localization:
If you add this aspect to a node, then the server will assume that all non-multilingual
properties apply to this locale.
-->
<aspect name="sys:localized">
<title>Translation</title>
<properties>
<property name="sys:locale">
<title>Locale</title>
<type>d:locale</type>
<mandatory>true</mandatory>
</property>
</properties>
</aspect>
I can imagine a whole lot of content where a locale does not make sense to me at all. Images, video, sound, code are a few examples. I would guess this locale is used for indexing tokenized string type properties. Still, I cannot see how that makes sense in the context of the content mentioned.
What exactly are the semantics of sys:locale and how is it used by Alfresco ?
The sys:locale serves as a fallback for the locale from the ContentData during indexing (if not set), so both #cm:content.locale and the tokenisation of d:content / d:text properties may / will be affected. In addition, sys:locale is used to differentiate the translations within the context of MultilingualContentService. On a site node, it affects the generated workflow descriptions for invitations.
sys:locale is not a real property in the sense that it is maintained in alf_node_properties - it is a virtual property much like sys:uuid derived from alf_node directly, which is why it affects even the content where it might not make much sense (apart from d:text property tokenization).
I have several <intercept-url> in my spring-security XML. I just have this small doubt. Suppose I have something like :
<intercept-url pattern="/data/**" access="ROLE_ADMIN" />
<intercept-url pattern="/**" access="ROLE_USER,ROLE_ADMIN" />
Since the below <intercept-url> has a pattern of /** I was wondering if the second URL over-rides the first one. E.g. I gt acess to /data/** even if I am a USER.
Quote from the reference documentation:
You can use multiple <intercept-url> elements to define different access requirements for different sets of URLs, but they will be evaluated in the order listed and the first match will be used. So you must put the most specific matches at the top.
As long as the rule for /** is listed later, it won't override the more specific rule for /data/**.
As jpprade suggested already, if you get access to /data/** as a plain user with the above rules, there must be some other problem with your configuration. In that case share your web.xml and the whole security config to troubleshoot that.
The second doesn't overides the first one, in theory it is the first matched rules which is applied.
if you can access /data/** as USER maybe it is because your miss something in the configuration, maybe the filter declaration ?