On Tue, Apr 3, 2012 at 6:23 AM, yunus <coolyunus1...@gmail.com> wrote: > I have two queries related to cayenne-
It would be best if you changed the subject and started a new thread for each new topic. > 1- I have a table "registration" in which there is a primary key > "EnrolmentId" which is autogenerated after successfully registration. Other > attributes are "Name" and "PAN ID".(PAN ID can belong to more than one > member of a family).So i want to know how i can find that a person cannot > register more than once.I want to find through combined search of (Name & > PAN ID) but these are not composite key as Enrolment id is already a primary > key.Now can you tell me how it can be done using Cayenne. 1 - there are many different ways to do this. See this url. http://cayenne.apache.org/doc/queries.html I would generally do it with a SelectQuery. Something along these lines: Expression nameExp = ExpressionFactory.matchExp(Relationship.NAME_PROPERTY, providedName); Expression panIdExp = ExpressionFactory.matchExp(Relationship.PAN_ID_PROPERTY, providedPanId); Expression qualifierExpression = nameExp.andExp(panIDExp); SelectQuery query = new SelectQuery(Registration.class, qualifierExpression); Note that if PanId is a foreign key to a Pan record rather than a number, you would do this instead: Expression panExp = ExpressionFactory.matchExp(Relationship.PAN_PROPERTY, providedPanObject); Please note that andExp() RETURNS the combined expression. It will not modify the first expression. A common mistake is to use "e1.andExp(e2)" instead of "e3 = e1.andExp(e2)". The value of e1 will not change. And lastly, if it's not obvious from the docs, you can put these all together if you desire. Expression qualifierExpression = ExpressionFactory.matchExp(Relationship.NAME_PROPERTY, providedName);.andExp(ExpressionFactory.matchExp(Relationship.PAN_ID_PROPERTY, providedPanId);); > 2-How can i restrict cayenne to autogenerate the primary key.The scenario is > that i have a table "LOGIN" in which "UserID" is primary key and i dont > want it to be generated automatically.It is upto the user to create his > "userID" so how can i do that? 2 - You can set this in the Cayenne Modeler. Just turn off primary key generation and add the loginId attribute directly to the ObjEntity. At this point, you are responsible for assigning a value to it. However, this is a not the best design. You are better off creating a meaningless login_id primary key in your table and not using UserId as your primary key. What happens if you have a user who has a userId needs to be changed? You will have to find every reference to that user id in your database and change it. This might happen because you later on want to allow users to update their userid, or it might happen because a userid has an unacceptable value (obscene, for example). It is better to make userId a regular field in your table and simply check for uniqueness when creating them.