Ralph Cook

Ranch Hand
+ Follow
since May 29, 2005
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ralph Cook

You can get better help, in general, by giving the actual error message and the line to which it applies.

I assume you mean the compile error "The method getInstance() in the type DateFormat is not applicable for the arguments (int)" in the line

The problem is that getInstance does not take an int value, or in fact any value. I think the method you're looking for is getDateInstance(int).

11 years ago
It turns out that Hibernate makes a determination of whether to look up certain database information in the database metadata, and if it can't it can run into this bug/feature. In version 3.x of Hibernate, there is an unpublicized property hibernate.temp.use_jdbc_metadata_defaults which, when set to false in the hibernate configuration, bypasses the check and so doesn't run into this. It doesn't happen in version 4.

Now if I can just figure out where to download version 4 of Hibernate, or whether the "full text search" version they have on their sourceforge site IS version 4 of hibernate, I'll be all set.
I am learning Hibernate, using Derby in server mode on a Win7 machine, developing with eclipse. Java 1.6, Hibernate 3.6, Derby 10.8.

I have written a simple Hibernate configuration and one annotation-mapped class, along with a basic DAO subclass and a class to create users in a user table. I have double-checked (at least) that I have the right schema name, and the record the program writes does actually go into the database. But I don't know where this error is coming from and I think I must have something slightly wrong because I don't see other people posting about it anywhere.

config file:

main class:




and the error log:

It is a longer post than I'm used to making, but I don't think there's a much smaller hibernate example to be had.

I'm stumped. I've looked into stackoverflow, derby fora, hibernate fora, I've added the schema name that someone thought was necesssary, I've cut it down from the 4 classes it used to have mapped, I've made a lazy-init-of-static of the SessionFactory, I do not know what else to try. Does anyone have any knowledge or even suggestions?
I'm going to try once more, but this really deserves several pages of explanation from a book, not what I can type in in my spare time.

The calling routine wants to make use of a method named doStuff; this method accepts (and demands) one parameter, an integer.

The *calling* routine can pass any variable it wants to into the method; let's say it has three integers and it is going to doStuff() with all of them:

So, that's in the calling routine. Now, the doStuff code must have a variable name for the parameter that is passed into it. It isn't going to be the same as ANY of the names of variables used by any callers; one great usefulness of a method is that it can be called multiple times from multiple places, and each call can pass in whatever is needed at the time:

So x, y, and Z are indeed parameters "passed in"; you can think of them as each being called "factor" by the method while it is executing. The method does not know or care what the variable is called by the caller. In the same vein, stuffResult is known only to doStuff(); since it is the value returned by the method, its value is assigned to result1, result2, and result3 by our three calls. We end up with those being equal to 9, 15, and 24 respectively.

I hope that's more clear.

11 years ago
I think you may need to go back and study "methods".

When a method is called, it may (or may not) have one or more "parameters" passed to it. The place from which the method is called puts one or more names of variables in the parentheses following the method name, and the values of those are "passed to" the method.

The variable "factor" in the code above is a parameter variable; when that method uses the parameter passed to it, that is what it calls the variable.

So the calling code does something like: "int x = doStuff(y);"

That calls the method doStuff and passes it y, which must be a variable in the calling code. Then the doStuff method might look like:

public int doStuff(int factor)
int result = factor * 68;
return result;

In our tiny example here, when the call in the first code was made, doStuff would get the value of y and be able to use it with the name 'factor'.

If this is not clear to you, you are really going to need instruction on how methods work in a larger context than I am liable to type out here 8>)

11 years ago
Try thinking of it this way: s1 is an object that contains a reference to "abc". s2 is a reference to "abc".

The == operator only returns true if s1 and s2 point to the same object, and they do not. Both these objects do have the same value.
11 years ago
I think it is misleading because there is not enough support for a novice
to understand the parallels between the problem and the example. What is
it that represents the objects? What does the house price have to do with
anything? Why the price? My first thought was that the rolodex cards
were the objects, then I realized that wouldn't work, but only because I
already understood the concepts.

If you had supported it better, it might have worked: "Consider a House
class, instances of it as houses for sale, and rolodex cards as
object variables. It seems clear that any house has one and only one
address, and if two cards carry that same address, they're referring to
the same house. That's the equivalent of an == operator.

"Let us further suppose that you, as a house buyer, think that the
important things about houses are their neighborhoods and their prices. A
program dealing with houses could implement an "equals()" method on a
House class that compared two house variables on these criteria and
returned true if the criteria matched.

"So two rolodex cards could carry houses that passed equals(), but not ==.
Incidentally, the reverse cannot be true - if two objects pass ==, they
are supposed to also pass equals()."

And you are right, equals() can be defined to mean different things; my statement
could be taken to mean that ALL contents are compared, and you are right
that isn't true. In the house example, equals doesn't take into account
whether it is brick or shingle or siding; if houses have the same defined
equivalence the other things can be unequal.
11 years ago
I think some of the replies have been misleading, particularly the one about rolodex cards. Here is my take on your question.

The == operator and the equals() method do very different things. For the primitives (not including String, which is an object often mistaken for a primitive), == is all you can use.

For two object variables o1 and o2, the == operator will tell you if they point to the same object. If you were to code

then (o1 == o2) would return true.

The equals method tells you if two objects have the same contents. The definition of this depends on the class itself; for example, you could decide that an object representing a person was equal if all the name fields were equal, even if the object contained address information as well.

A word of caution if you play with this using Strings -- string literals in Java have rules that make it difficult to predict some things. Based on what I've said, you might expect:

to give you a situation in which o1 == o2 would be false. But it isn't, because the Java compiler remembers that you've already used the literal once, so it assigns a reference to one literal to both variables, making == for them true.

Playing with it using your own class would be preferable. And I think it's less confusing to think of it without the "hex code" or "address of the object" kind of explanation, myself.
11 years ago
The other thing that may not be obvious is that, within the method change(), the statement

assigns a value to an instance variable within the same rt object referenced by the caller . But the statement

creates a new Integer object to assign and assigns it to intt.

So the second statement changes the value of the object reference itself, and that does not affect the caller's reference.

You can read more about the creation of a new object for Integer by looking up "autoboxing".
11 years ago
You do not say how you obtained this string; I recommend giving us code, hopefully running code, so we can see how it is obtained. It appears to be a string returned from an array of Object.
11 years ago
We need more information - what is a DSN? What errors do you get? etc.
11 years ago
You cannot dereference a primitive type. Whatever code you wanted to be run as your method isDuplicate(), it cannot be a method on int.

Perhaps what you meant to do was calculate a birthdate and store it in a separate int variable, then determine if the array at that int position had already been visited.
12 years ago
I suppose you could still call static methods on such a class, but I'd hardly call that a reason for having an abstract class that isn't extended. Sounds like one of those nice 'trivia' 'gotcha' questions some interviewers like.
12 years ago
Assuming your file can contain multiple lines for one client, there is no way to calculate the discount based on total bill until you have processed all the lines in the file. Therefore you are going to have to accumulate information for each client as you go through the file. You don't say whether the "work on 1000 acres" has to be on one line in the file or not; if it does, you can calculate that in your "computeBill" routine, which appears to be called for one line. But after you're done accumulating things for all clients (either totalling them as you go or keeping an object per line organized by client), then you can see what their total bill is to give them the 10% discount.
12 years ago

Johan Mena wrote:

Praveen Kumar M K wrote:Can you cheat with a temporary array?

If yes, you can do a single traverse of your sorted array and fill in the temp array each time you encounter a newer element. Your newly created array will be duplicate free.

I could, but that would defeat my goal of O(N).

No, you would compare each element to one other element, and you would move all of the elements once. Both my scheme (done in place) and the separate array idea are O(N).
12 years ago