Criteria api Restriction of foreign key - hibernate-criteria

i'm using Hibernate criteria api in my java ee app. I have two Agenda interface in witch i use jsf/primefaces schedule. the first one get data with the method findall() but the second one get data with the method findByCriteria(cri). in the cri variable i have to compare a foreign key with null value
like this:
Criterion cri= Restrictions.eq("demande",null);
listIntervention=interventionService.findByCriteria(cri);
this syntax it doesn't work
can some one help me? thanks in advance

You should use Restrictions#isNull. That one is used for comparing of NULL values.
Criterion cri = Restrictions.isNull("demande");

Related

How AWS DynamoDB query result is a list of items while partition key is a unique value

I'm new to AWS DynamoDB and wanted to clarify something.
As I learned when we use query we should use the partition key which is unique among the list of items, then how the result from a query is a list!!! it should be one row!! and why do we even need adding more condition?
I think I am missing something here, can someone please help me to understand?
I need this because I want to query on list of applications with specific status value or for specific range of time but if I am supposed to provide the appId what is the point of the condition?
Thank you in advance.
Often your table will have sort key, which together with your partition key will create composite primary key. In this scenario a query can return multiple items. To return only one value, not a list, you can use get_item instead if you know unique value of the composite primary key.

managing unique values across a complete list in SharePoint

I am trying to populate unique values across a multiple columns in a SharePoint list. For example if we have "column A" with value "X", none of the columns should accept the value "x" in the entire list.
Is it possible?
I tried the formula using an example.
=IF([columnA]=[ColumnB],TRUE,IF([ColumnB]<>"",TRUE,FALSE))
But i felt stupid as i had no idea why i feel it is right. But it doesn't work
Any simple and better ideas will be a great help!
I think you need PreSaveAction for this requirement, when item saving, the function will execute for client side validation, then you could call rest api to validate column A value and user input value, when return false, means validation failed and item will not save.
Demo thread.
https://sharepoint.stackexchange.com/questions/255633/limit-edit-in-sharepoint-list-to-only-3-items-per-user
SharePoint rest api filter.
https://www.c-sharpcorner.com/article/sharepoint-2013-using-rest-api-selecting-filtering-sortin/

C++: How to set GUID to NULL instead of GUID_NULL?

I have a database which uses GUIDs instead of, say, an ordinary counter for the ID fields. But I can't seem to put NULL (instead of GUID_NULL) into such fields in DB even though. Yes, the field in the database does take NULL.
Let's say there is a parent-child relationship between two tables. So there is a parent and a child GUID references from one table to another. But the "root" parent does not have any parent and there I would like to be able to put NULL into its ParentUID database field. If I put GUID_NULL there then I will need a corresponding default row in the referenced table which has a GUID-value of GUID_NULL so that the foreign key constraint won't break.
Also, using GUID_NULL with default-rows at referenced tables will give me a resultset back when doing a standard join operation...which is not desirable.
They way it's done in code when inserting values into database is using a CCommand which takes structure that contains the values of the row fields to be inserted. One of these is a GUID type variable.
So it creates an SQL statement string looking like
INSERT INTO [tablename] (field1, field2, field3,...) VALUES(?,?,?,...)
and then in a loop there is something like:
command.field1 = 1;
command.field2 = 2;
command.GUIDField = ?????? //I want to put NULL here instead of GUID_NULL
command.Open(...);
I hope it is understandable what I wish to do and what the conditions in code are.
Thankful for help!
UPDATE:
Ok, it was very hard to exaplin correctly, but this is exactly what I want to do http://support.microsoft.com/kb/260900
Just that when I follow that example, it makes no difference...still I get FK constraint violation on insert so I suspect it is trying to insert GUID_NULL instead of NULL. :(
The link I had in my Update-section does work, my bad: http://support.microsoft.com/kb/260900
It is the answer to my problems, perhaps it will help someone else as well! :3

SharePoint UserData and the ;# Syntax in returned data

Can a SharePoint expert explain to me the ;# in data returned by the GetListItems() call to the Lists web service?
I think I understand what they are doing here. The ;# is almost like a syntax for making a comment... or better yet, including the actual data (string) and not just the ID. This way you can use either, but they are nicely paired together in the same column.
Am I way off base? I just can't figure out the slighly different use. For example
I have a list with:
ows_Author
658;#Tyndall, Bruno
*in this case the 658 seems to be an ID for me in a users table somewhere*
ows_CreatedDate (note: a custom field. not ows_Created)
571;#2009-08-31 23:41:58
*in this case the 571 seems to be an ID of the row I'm already in. Why the repetition?*
Can anyone out there shed some light on this aspect of SharePoint?
The string ;# is used as a delimiter by SharePoint's lookup fields, including user fields. When working with the object model, you can use SPFieldLookupValue and SPFieldUserValue to convert the delimited string into a strongly-typed object. When working with the web services, however, I believe you'll need to parse the string yourself.
You are correct that the first part is an integer ID: ID in the site user list, or ID of the corresponding item in the lookup list. The second part is the user name or value of the lookup column.
Nicolas correctly notes that this delimiter is also used for other composite field values, including...
SPFieldLookupValueCollection
SPFieldMultiColumnValue
SPFieldMultiChoiceValue
SPFieldUserValueCollection
The SPFieldUser inherits from the SPFieldLookup which uses the ;# notation. You can easily parse the value by creating a new instance of the SPFieldLookupValue class:
string rawValue = "1;#value";
SPFieldLookupValue lookupValue = new SPFieldLookupValue(rawValue);
string value = lookupValue.LookupValue; // returns value

Comparing entities while unit testing with Hibernate

I am running JUnit tests using in memory HSQLDB. Let's say I have a method that inserts some values to the DB and I am checking if the method inserted the values correctly. Note that order of the insertion is not important.
#Test
public void should_insert_correctly() {
MyEntity[] expectedEntities = new MyEntity[2];
// init expected entities
Inserter out = new Inserter(session); // out: object under test
out.insert();
List list = session.createCriteria(MyEntity.class).list();
assertTrue(list.contains(expectedEntities[0]));
assertTrue(list.contains(expectedEntities[1]));
}
The problem is I cannot compare expected entities to actual ones because the expected's id and the actual's id are different. Since setId() of MyEntity is private (to prevent setting id explicitly), I cannot set all of the entities' id to 0 and compare like that.
How can I compare two result set regardless of their ids?
I found this more practical. Instead of fetching all results at once, I am fetching results according to the criterias and asserting they are not null.
public void should_insert_correctly() {
Inserter out = new Inserter(session); // out: object under test
out.insert();
Criteria criteria;
criteria = getCriteria(session, 0);
assertNotNull(criteria.uniqueResult());
criteria = getCriteria(session, 1);
assertNotNull(criteria.uniqueResult());
}
private Criteria getCriteria(Session session, int i) {
Criteria criteria = session.createCriteria(MyEntity.class);
criteria.add(Restrictions.eq("x", expectedX[i]));
criteria.add(Restrictions.eq("y", expectedY[i]));
return criteria;
}
A stateful entity should not override equals -- that is, entities should be compared for equality by reference identity -- so List.contains will not work as you want.
What I do is use reflection to compare the fields of the original and reloaded entities. The function that walks over the fields of the objects ignores transient fields and those annotated as #Transient.
I don't find I need to ignore the id. When the object is first flushed to the database, Hibernate allocates it an id. When it is reloaded, the object will have the same id.
The flaw in your test is that you have not set transaction boundaries. You need to save the objects in one transaction. When you commit that transaction, Hibernate will flush the objects to the database and allocate their ids. Then in another transaction load the entities back from the database. You will get another set of objects that should have the same ids and persistent (i.e. non-transient) state.
I would try to implement Object.equals(Object) method in your MyEntity class.
List.contains(Object) uses Object.equals(Object) (Source: Java 6 API) to determine if an Object is in this list.
The method session.createCriteria(MyEntity.class).list(); returns a list of new instances with the values you inserted (hopefully).
So you need to compare the values. This is easily done via the implementation of Object.equals(Object).
Clarification edit:
You could ignore the ids in your equals method, so that the comparison only cares about "real values".
YAE (Yet Another Edit):
I recommend reading this article about the equals() method: Angelika Langer: Secrets Of Equal. It explains all background information very well.