java

How to get a unique key for two fields with Hibernate?

I have two fields of an entity class which I don't want to be unique but to instead be used as composite fields for a key which must itself be unique. For example I have two fields (name and version) which can be the same for other records but together they must be unique. What is the best way to do that using Hibernate (with annotatio...

Convert Bytes to bits

Hi, I'm working with java. I have a byte array (8 bits in each position of the array) and what I need to do is to put together 2 of the values of the array and get a value. I'll try to explain myself better; I'm extracting audio data from a audio file. This data is stored in a byte array. Each audio sample has a size of 16 bits. If t...

Logger.DebugFormat in log4j

I'm used to working with the excellent log4net, and I assumed log4j is a direct port or ancestor. I'm looking for an equivalent to the useful Logger.DebugFormat() family of methods, and I can't find anything like it. Is there anything like that in log4j (or similar packages)? If not, why not? ...

Ctrl-tab in IntelliJ IDEA

Can I configure IntelliJ on Windows to use Ctrl-Tab for switching between files? Googling finds this old thread that says "no". ...

The indestructibles - HTTP Parameters

I always wondered why there exists no removeParameters() method in Servlet API. What could be the motive behind this design? Here is a scenario: I am posed with a challenge in a proprietary MVC framework that I am compelled to use. This framework uses a Controller Servlet that hosts an algorithm in it's post method: doPost() { //creat...

Hibernate is *NOT* throwing an exception (I think it should)

The Hibernate JavaDoc states that Session.update(Object o) would raise an exception if there's already a persistent instance of o, right? If there is a persistent instance with the same identifier, an exception is thrown. However, the following code doesn't throw anything when I run it. And I think it should! Email email = new Email("...

JNA : EXCEPTION_ACCESS_VIOLATION

Hi, I use JNA to call this function in libpotrace.dll, this function is potrace_state_t *potrace_trace(const potrace_param_t *param, const potrace_bitmap_t *bm); parameters in library: typedef unsigned long potrace_word; struct potrace_bitmap_s { int w, h; /* width and height, in pixels */ int dy; /*...

Matcher.appendReplacement with literal text

I am using Matcher.appendReplacement() and it worked great until my replacement string had a $2 in it: Note that backslashes ( \ ) and dollar signs ($) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string. Dollar signs may be treated as references to ...

How to explore which classes are loaded from which JARs?

Is there a way to determine which classes are loaded from which jars at runtime? I'm sure we've all been in JAR hell before. I've run across this problem a lot troubleshooting ClassNotFoundExceptions and NoClassDefFoundErrors on projects. I'd like to avoid finding all instances of a class in jars and using process of elimination on the...

Is Hibernate worse than NHibernate?

How does Hibernate compare to NHibernate? I've heard the claim that "Hibernate is much worse than NHibernate, even to the point of not using it (and using JDBC over it)". Can anyone support or refute this? Update - I am not trying to decide between them. Our DAL team decided to use NHibernate for our .Net side, but not use Hibernate on...

Essential "code toolset" for java/.Net

What essential code packages do you use on every project, that's not included in the BCL or java distribution? Mocking/Stubbing Unit Tests IOC / Dependency Injection Logging ORM ... Which implementation of the above do you use? What essentials did I miss? ...

Need Spring version# - only have spring.jar file

I've inherited an app that uses Spring. The original developers are not available. The Spring jar file is just "spring.jar", so there's no version# in the filename to help me. I'd like to download the Spring source corresponding to the jar file. The MANIFEST.MF file has "Spring-Version: 1.2" however that's not precise enough. I've looked...

How to list contents of a server directory using JSP?

When writing a JSP file, how can I get the current directory of this file at runtime (to be able to iterate the directory and list its contents)? Would some file I/O operations be restricted because of some security issues? I would prefer a solution without accessing some implementation-specific server variables / properties. EDIT: I ...

Overriding JCS events

I am using Apache JCS in our application to cache commonly used data at application start-up. However, if some of the data in cache is not used till its idle time, I want to manually reload that value from database. So, basically I want to over-ride the JCS events such that my java program is aware of instants when a key is getting re...

Is it worth learning Java libraries if I'm not going to actually use Java?

So I've been programming in PHP and Python (and recently Ruby), and I was just wondering: should I just Java-based languages (or the Java implementations of languages) from now on, to take advantage of the immense collection of Java libraries? Would that really benefit me as much as I think it would, or am I crazy? For example, let's sa...

JSP Custom Tags: Is it possible to have a more than start / close tags?

After using the Django template language, I really miss being able to do things like this: {% if condition %} <!-- snip --> {% else %} <!-- snip --> {% endif %} When I am using JSP, I am stuck doing something like this: <logic:equal name="something" value="example"> <!-- snip --> </logic:equal> <logic:notEqual name="somet...

Servlet security authentication

How to make security authentication for a web application that is using servlets and .jsp. I want to make authentication using tomcat. Can anyone explain steps I need to take in servlet and jsp for FORM authentication. Servlet is taking care of .jsp page that needs to be secured. ...

different using. java.util.Enumeration and Iterator

what is the exact different of both.. is using enumeration more benefit than using iterator..? can anyone elaborate.. any reference article would be appeciated ...

Application server - to use or not use?

Typically we use WebLogic or JBoss to deploy our apps. I understand that when using open source solutions like Spring you can develop your app and run it on a simple servlet container like Jetty. So the question would be why even bother with an app server? ...

RecvFrom() returns packet larger than sender NIC MTU

I have proprietary application sending out multicast packet to the network. It is running on the linux with NIC MTU 1500. And then I write a simple java program to using MulticastSocket class to receive message. I found it is DatagramPacket size is ~7900. The receiver program is running on the linux with NIC MTU 1500. I rewrite the pro...