While reading through the Hibernate documentation, I keep seeing references to the concept of a natural identifier. Does this just mean the id an entity has due to the nature of the data it holds? E.g. A user’s name + password + age + something are used as a compound identitifier? Answer In Hibernate, n…
Tag: java
Running out of java heap space- 15 puzzle problem
G’day all, I tried the solution for eight puzzle problem posted here by joel Neely and played around with it and modified it so that can be used to solve for higher grids[Changed the String representation of the grid to two dimensional integer representation and modified the logic accordingly]. However …
Cannot issue data manipulation statements with executeQuery()
In MySQL I have two tables, tableA and tableB. I am trying to execute two queries: But I get the following error: What does this mean? Answer To manipulate data you actually need executeUpdate() rather than executeQuery(). Here’s an extract from the executeUpdate() javadoc which is already an answer at …
Get type of a generic parameter in Java with reflection
Is it possible to get the type of a generic parameter? An example: Answer One construct, I once stumbled upon looked like So there seems to be some reflection-magic around that I unfortunetly don’t fully understand… Sorry.
Why is Java faster when using a JIT vs. compiling to machine code?
I have heard that Java must use a JIT to be fast. This makes perfect sense when comparing to interpretation, but why can’t someone make an ahead-of-time compiler that generates fast Java code? I know about gcj, but I don’t think its output is typically faster than Hotspot for example. Are there th…
Definition of Java’s CMS GC log lines?
Examining a Java runtime with CMS (Concurrent-Mark-Sweep) GC enabled, what is the definition of the CMS space in the logs below? Shall I assume it is the tenured space? I see the following lines of a minor-major-minor GC event In particular the [CMS: 10899K->9379K(12448K), 0.2675281 secs] at the 23.492 eve…
How to handle a static final field initializer that throws checked exception
I am facing a use case where I would like to declare a static finalfield with an initializer statement that is declared to throw a checked exception. Typically, it’d look like this: The issue I have here is that the ObjectName constructor may throw various checked exceptions, which I don’t care ab…
Java error: Only a type can be imported. XYZ resolves to a package
I get the error: “Only a type can be imported. XYZ resolves to a package.” Someone has explained the cause here but I am not sure what I supposed to do to fix this. FYI: I am using Eclipse. I have added the code that does the importing below. The java.util.* import works fine. Edit: the actual err…
Suppress deprecated import warning in Java
In Java, if you import a deprecated class: You get this warning: The type SomeDeprecatedClass is deprecated Is there a way to suppress this warning? Answer To avoid the warning: do not import the class instead use the fully qualified class name and use it in as few locations as possible.
Byte order mark screws up file reading in Java
I’m trying to read CSV files using Java. Some of the files may have a byte order mark in the beginning, but not all. When present, the byte order gets read along with the rest of the first line, thus causing problems with string compares. Is there an easy way to skip the byte order mark when it is prese…