Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!

Bhavin Sanghani

Ranch Hand
+ Follow
since Dec 17, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bhavin Sanghani

Hi

I want to restrict few queries while fetching the data. I have kept lazy="false" in my code with fetch="subselect" and "join" as appropriate. Now, I want to fetch objects upto one level and at second level except one association i want to discard everything in query. e.g.

In following mapping strucutre, I want to load all QuestionsAnswer with Question & Answer objects only and not Feature which has association in Answer:




Any idea how can I do this?

Thanks,
Bhavin
Hi

In my application I am using map-backed form. I am using it to store responses of the user for one survey based system. For example,


1) Question1
a) Yes
b) No

2) Question2
a) Yes
b) No


In this example, Question2 will only be displayed if user selects "Yes" answer of Question1.

Now, this captures responses properly and storing it in the map available in the form. But if user changes the response from Yes to No in Question1 then I need to remove response of Question2 from map available in form. Since user had answered Question2 it is still available there.

Can anyone adivce me to fix this issue?

Thanks,
Bhavin

11 years ago
Hi,

Anyone knows the tool which can suggests defects in hibernate mapping files if any.

Thanks,
Bhavin
What I am trying to achieve is : Allowing admin to create dynamic questionairre form. So, admin can create Pages, Sections, Questions, Answers and associate Rules with them.
[ December 26, 2008: Message edited by: Bhavin Sanghani ]
Hi,

Thanks for your reply.

Yes, actually I have many joins and thought to use left outer join in DAO and process the data. But simultaneously I did not like that I am not able to use ORM here. I am confused whether its a limitation of ORM to support this kind of functionality? Or explicit left outer join is much more powerful in this case? Lazy loading would fire many queries while rendering the data of each node in depth...since at every tree level node type has different type...e.g. level 0 - ClassA, level 1 - Class B etc.
Hi,

I have few classes and between them one-to-many relationship exists. e.g.

One Object A can have many Object Bs.
One Object B can have many Object Cs.
and list goes on upto 6-7 levels. You can think of "tree" structure.

Now, I require to fetch data of all the objects. I am trying to figure out betch fetching strategy:

1) I keep lazy loading but then also it would fire many queries
2) If I go for eager loading then it ends up with n+1 select problem
3) If I use left outer join then single query can give me the result but I would require to process on the list of resultsets in DAO and final list I need to send at web layer.
4) If I use join fetch then gets "can not fetch multiple bags" error


Can anyone suggests best approach if any or similar example explained online?

Thanks,
Bhavin
I think, with this approach it would be a problem if you are logging all the actions (INSERT, UPDATE, DELETE) in the database. You may have to write separate logic to log actual transaction..isn't it?
Hi,

Other than cross platform thing, should we consider cost of loading object before updating it?

Thanks
Bhavin
[ December 09, 2008: Message edited by: Bhavin Sanghani ]
Hi,

I want to create Object Graph from three (or more) related tables by querying it with criteria. I have learnt that using left join fetch we can do it in single query but it seems there are certain limitations.


I have following mappings:

Question.hbm.xml
<class name="Question" table="QUESTION">
<id name="questionId" type="java.lang.Long" column="QUESTIONID" >
<generator class="increment" />
</id>
<property name="questionName" type="java.lang.String" column="QUESTIONNAME" length="500" />
<many-to-one name="questionType" column="QUESTIONTYPEID" class="QuestionType"/>
<many-to-one name="questionSet" column="QUESTIONSETID" class="QuestionSet" not-null="true" fetch="join"/>
<one-to-one name="comment" class="Comment" property-ref="question" cascade="all"/>
<one-to-one name="matrix" class="Matrix" property-ref="question" cascade="all"/>
<bag name="answers" inverse="true" cascade="all, delete-orphan" lazy="false">
<key column="questionId"/>
<one-to-many class="Answer"/>
</bag>
<bag name="matrix" inverse="true" cascade="all, delete-orphan" lazy="false">
<key column="questionId"/>
<one-to-many class="Matrix"/>
</bag>
<bag name="features" inverse="true" cascade="all" lazy="false">
<key column="questionId"/>
<one-to-many class="Feature"/>
</bag>
<bag name="rules" cascade="all" lazy="false">
<key column="questionId"/>
<one-to-many class="Rule"/>
</bag>
</class>


Answer.hbm.xml:

<class name="Answer" table="ANSWER">
<id name="answerId" type="java.lang.Long" column="ANSWERID" >
<generator class="increment" />
</id>
<property name="answerName" type="java.lang.String" column="ANSWERNAME" length="50" />
<many-to-one name="question" column="questionId" class="Question" not-null="true" fetch="join"/>
<bag name="features" cascade="all" lazy="false">
<key column="ANSWERID"/>
<one-to-many class="Feature"/>
</bag>
</class>



Similar way Features.hbm.xml and Rules.hbm.xml. Now, I want to pass questionSetId (parent) and bring all the records in the collection and do the processing...

1) Is this preferred approach?

2) If yes, then it fires lots of queries. Should I fire explicit queries and create Object Graph manually? How can I avoid lots of queries and create Object Graph in one (or minimal) query.

3) If no, can you advice me for preferred approach in this example?

I am using Table per Concrete Class approach.


Thanks,
Bhavin




Thanks,
Bhavin
[ December 09, 2008: Message edited by: Bhavin Sanghani ]
Hi,

I want to fire query using Hibernate to update specific field. Here, I dont have object in the memory so, other fields will have null value.

If I try SaveOrUpdate() call then it will overwrite null values to other fields.

I can retrieve the object, populate it and then fire saveOrUpdate() but this looks me inefficient.

I can use SQL query but I am wondering if any better approach is available.

Please guide.

Thanks,
Bhavin
Thanks. I tried "return false;" at end of ajax call and it submits one request but it does not populate form fields in actionForm.

can anyone give example of Jquery + Struts 1?

Thanks,
Bhavin
11 years ago
Hi,

I am using JQuery with Struts 1.1. I am using following code when user
clicks on Save button:


$('#save').click(function() {
$.blockUI({ message: "Please wait..." });


$.ajax({
url: '/saveData.do?dispatch=save',
type:'post',
cache: false,
dataType:'xml',
complete: function() {
$.unblockUI();
}
});

In my struts code,

<html:form action="/saveTemplate.htm?dispatch=save" method="POST">
<div id="firstchildcontainer">
Name: <html:text property="templateName"/>
Description: <html:textarea property="description" rows="8"
cols="10"/>
<html:submit styleId="save"><bean:message key="button.save"/></
html:submit>
<html:cancel styleId="cancel"><bean:message key="button.cancel"/></
html:cancel>
</div>
</html:form>


The problem here is it is submitting request twice because it is
defined with struts form and with url (in ajax). How can I avoid
duplicate request?


Thanks,
Bhavin
11 years ago
Hi,

I want to submit data on popup, save it, close popup and show the saved data on parent page. I am using struts 1.3 environment. I tried using following ways:

1) Using Javascript, I submitted form data from popup and reloading parent page. This reloads parent page but it seems that it does not give surity of processing transaction successful. Any idea whether this approach is appropriate?

2) Using Struts, end of the "saveAction" of popup, I am forwarding it to "editAction" of parent page with expectation to bring the data and show it on the parent page. But this does not work. Any idea how it works in Struts?


Thanks,
Bhavin
11 years ago
I tried that but the problem is to re-issuing the request and start new session from view, I think...so, transaction wil be committed and new session wil be started...