Win a copy of Head First Android this week in the Android forum!

Sandeep Jindal

Ranch Hand
+ Follow
since Aug 25, 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
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sandeep Jindal

Hi All,

Can you suggest some good sites to post general technical articles on Java. I am looking for sites like javaworld, theserverside, etc.
10 years ago
Hi All,

I am using following data model (changed to make it simpler).

Table: STUDENT, TEACHER, BOOKS_ASSOCIATION, BOOKS_DETAILS.

Student and Teacher have a column whose forign key is BOOKS_ASSC_ID, hbm mapping as following


Books Association Mapping is as following:


and the BOOK_DETAILS table has a coulmn refering to BOOKS_ASSOCIATION table.

The general idea is, the main entity(student,teacher, or anybody else) can have many books. Thus they are having ref to an association key which in turns refer to book details table.

Why there is no direct one to many mapping between main entity (student, teacher, anybody else) is because, books can be issued to any of the main entity. Thus, in order to maintain the forign key reference in BOOK_DETAILS table, this is done.

Now, the problem: Suppose, a Student has issued five books already. Now if I add one more book to the booksDetails set and update the Student object, hibernate runs one insert statement (which is fine), but also runs 6 update statements considering that I have not updated anything in the rest 5 books. I dont want to update the previous items in the association set.

Is there any way to do so? Please also note that I can live with, never updating the BOOK_DETAILS from BOOKS_ASSC or parent entity (STUDENT, TEACHER, etc). I just want two operatonsL: 1) retrieve and 2) add into the bookDetails set.

I tried using cascade="create", but this is not supported. Can anybody please suggest the solution to the problem?
Thanks for the reponse! That answers: Using Enum is better because it is type safe. Using Enum is not better because we need to do little extra coding.

Are there any further reasons/comparison between these two. E.g. Memory Footprint, Performance?

11 years ago
Hi All,

A very basic question. I have a VO, where in for one member variable I have option of storing either:
a) a long value, id
b) Enum


MY VO could be:



In general which one is better?

Or side questions could be:
If we need to compare long value (e.g. long1 == long2) and navType.FINAL.equals(NAVType.Final), which one is better?

I do understand, that memory footprints of using Enum is better than using Long.
11 years ago
Hi Jeanne,

Thanks for the reply. I understand its not obvious. What I thought one way of doing it is:

I have a machine where SVN server is installed. This machine is using a proxy. That means outside world cannot directly access the SVN server, right?
Now there is some service provide. I register my machine to that provider which means that service provide knows me when I am online and can send and receive data to some utility (something like gtalk) which intern sends talk to my SVN server.

Now the user with SVN client(say eclipse) would talk to that service provider which would forward the data to my svn client.

Something like this is possible? Or some other solution is possible?

Actually I am working on a small project thus don't want to spend on buying static IP or some space for SVN. If the above does not work, can you suggest some good sites which provide free hosting of personal (not open source) project with 2 or more client access?

Regards
Sandeep
Hi,

I have an SVN server installed on my machine. But since I am using a router to connect to internet, people are unable to ping/connect me. That means they cannot access my SVN server using the IP from whatismyip.com website.

Is there a way by which people connect to some utility (e.g. teamviewer) which would be installed on my machine and that utility intern talk to SVN server I already have?

If the above is not possible, is that any solution to the problem (connect to version control server without knowing the IP of the server but by some other means).

Regards
Sandeep
Thanks for the replies.

I got my answer/clarification. The behavior if calendar is not same as of my requirement. I need to write the code, similar to written by Jesper.

Thanks again.

11 years ago
Hi,

I am using the following code:



The output is following:


I was wanting to have output as

which should be in-line with JavaDoc of Calendar:

Usage model. To motivate the behavior of add() and roll(), consider a user interface component with increment and decrement buttons for the month, day, and year, and an underlying GregorianCalendar. If the interface reads January 31, 1999 and the user presses the month increment button, what should it read? If the underlying implementation uses set(), it might read March 3, 1999. A better result would be February 28, 1999. Furthermore, if the user presses the month increment button again, it should read March 31, 1999, not March 28, 1999. By saving the original date and using either add() or roll(), depending on whether larger fields should be affected, the user interface can behave as most users will intuitively expect.



Can anybody please explain the reason for the behaviour and probably the way to get the desired result too.

Regards
Sandeep Jindal


11 years ago
Yes Patricia , exactly!

And since {1,1} is {Order ID, No Of Orders}, thus
adding {1,1} into {1,2} shall result in {1,3} and
adding {1,1} into {2,2} shall result in {2,2}, {1,1}

Hope that solved confusion
11 years ago
I am sorry, I might have confused you.

I put it another way. I have Orders and Order's Residuals.
Since I need to get Residuals for a particular type of order, I am strong it in a Map<Orders, Residuals> Is that fine?

Now, Orders which is a key, is a Map<ID[Integer], Number[Integer]> (this map is not a problem).
Say my Initial state is this.

Order<{1,1}>, Residual1
Order<{1,2}>, Residual2
Order<{2,2}>, Residual3



Now, for each of entry in this Map, I need to add one more Order <{1,1}> which shall result the following:

Order<{1,2}>, Residual1
Order<{1,3}>, Residual2
Order<{2,2}, {1,1}>, Residual3




I understood what Jesper said and one of the right ways but it would work for me, unless I remove all and then start adding and for this, I am temporary saving the keys in list.
11 years ago
Hi Campbell,

Thanks for your answer.
To explain you the scenario:
I have Order ID and Number of Orders. For this I store some information.
e.g.

(OID: 1, NO 2 AND OID: 2, NO. 3 ) is one key
(OID: 2, NO 3 AND OID: 4, NO. 3 ) is another key



Now, I as part of my algoirthm, I need to store and get Information for this Key (OrderID, Number).

Also, in some process of my algorithm, say I got I more order and I need to add this in each key.
Say I got another OID:6, No.1. I need to add this into each key and my keys wills be

(OID: 1, NO 2 AND OID: 2, NO. 3, OID:6, No.1 ) is one key
(OID: 2, NO 3 AND OID: 4, NO. 3, OID:6, No.1 ) is another key



I could have used different approach, but I frequency need Values based on the keys mentioned above.

This is my scenario and I need to update keys for some operation.

I totally agree with you that they List approach I mentioned is very bad in term of HashCode, but this is the best I could think of.
11 years ago
Thanks Jesper!

What I have done is (even before your reply) following:

I have taken all the key and put that into an ArrayList.
Now, I iterated the arraylist and changed the values of the keys (and since its refences, it has changed the corrospding keys)

Ofcourse, I have taken care that the hashcode for all these key is same(which was very important).

Please comment on this, if you think this is not the correct or not the best approach.
11 years ago
Thanks for your answers.
Understand the contract of HashMap which says do not play with keys, or never play with keys atleast when iterating (correct?)

but what if I have a requirement in such a way that I need to update my keys based on some operations and that is my requirement.
Can you please suggest what to do in that case.

Example of my requirement is:
I maintain No of Order and the residuals of that orders.
While doing some operations, I need to modify the No Of orders.

Also, I need to maintain Map whose key is No Of orders because I frequently require to get the residuals for a particular no of orders (in short, I need some value based on some key(no of orders) and that key needs to be modifiable).
What do the experts suggest in this case?

Regards
Sandeep Jindal
11 years ago
Hi Campbell,

Thanks for the Quick and detailed reply.

I understand the issue. The issue was the original Key have id as 2 had hashCode as 2 and they key is stored with this hashCode in Map.
Now I change the value of key to 1. Thus when i try to remove key(1), it removed the key whose hashCode is 1 and value is 1 (as implemented in the code), thus key(2) whose hash code was 2 is never removed. Please correct if my understanding is wrong.


On the side note, can you please comment on why the equals method is poorly designed? (I might be missing some basic design principle)

Thanks
Sandeep Jindal
11 years ago
Hi All,

I was trying to do the following thing with HashMap.

I create a Map<Key, String>


Idea of this key class is that the object of Key is same if value in i is same.

Now, I created the following Map.



Now, I change the Key Key(2) such that value of i in it is 1 which is same as of the Key(1).



Now, the Map has two key which actually equals, which is not possible if we add the keys using Put method.
Also, on getting previous one is generated.

This is fine.

But the interesting part is that when i remove the key

only one key is lost.

Also, if I removed once, I cannot retrieve the re

That means the Key whose value was 2 is lost (another memory leak in Java). Can anybody explain/put his thoughts on this behavior?
Or can anybody answer the followings?
1. Why only first object is returned and not second (always) when there are two keys.
2. When removing the key, why did not it remove both?
3. Why did map.containsValue("2") returned true, even when after removed the key?



11 years ago