annotations

How to use Hibernate @Any-related annotations?

Could someone explain to me how Any-related annotations (@Any, @AnyMetaDef, @AnyMetaDefs and @ManyToAny) work in practice. I have a hard time finding any useful documentation (JavaDoc alone isn't very helpful) about these. I have thus far gathered that they somehow enable referencing to abstract and extended classes. If this is the case...

Compass Search Annotations cause compiler errors

I'm trying to use the @Searchable annotations from the Compass search engine in my Java program, but I receive a compile-time error: "type mismatch: cannot convert Searchable to Annotation". I have included all of the jar files that I can think of, and scoured the web for working examples to no avail. Does anyone have a working example...

Use AJAX instead of TagLib?

I was thinking about the idea of using Ajax instead of TagLib. The most elegant way would be: Using Java Annotation. The idea is, designers or anybody can make the HTML without any taglib ,just using the "standard" HTML tags with id or name, and call the Javascript. That way any WYSIWYG can be used, developer don't have to care about HT...

Scanning Java annotations at runtime

What is the best way of searching the whole classpath for an annotated class? I'm doing a library and I want to allow the users to annotate their classes, so when the Web application starts I need to scann the whole classpath for certain annotation. Do you know a library or a Java facility to do this? Edit: I'm thinking about somethin...

Create Annotation instance with defaults, in Java

How can I create an instance of the following annotation (with all fields set to their default value). @Retention( RetentionPolicy.RUNTIME ) public @interface Settings { String a() default "AAA"; String b() default "BBB"; String c() default "CCC"; } I tried new Settings(), but that does ...

Hibernate/JPA Annotations -- Unknown Entity

An application that has been working well for months has stopped picking up the JPA @Entity annotations that have been a part of it for months. As my integration tests run I see dozens of "org.hibernate.MappingException: Unknown entity: com.whatever.OrderSystem" type errors. It isn't clear to me what's gone wrong here. I have no hiber...

Cross-class-capable extendable static analysis tool for java?

I'm trying to write rules for detecting some errors in annotated multi-threaded java programs. As a toy example, I'd like to detect if any method annotated with @ThreadSafe calls a method without such an annotation, without synchronization. I'm looking for a tool that would allow me to write such a test. I've looked at source analyze...

Hibernate Annotation Placement Question

Hi -- I've got what I think is a simple question. I've seen examples both ways. The question is - "why can't I place my annotations on the field?". Let me give you an example.... @Entity @Table(name="widget") public class Widget { private Integer id; @Id @GeneratedValue(strategy=GenerationType.AUTO) public Integer getId() { retu...

Configurable values to MDB annotations

I'm trying to use this method for receiving mail in our EJB3 app. In short, that means creating an MDB with the following annotations: @MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "mailServer", propertyValue = "imap.company.com"), @ActivationConfigProperty(propertyName = "mailFolder", propertyValue = ...

OSGi/Felix Declarative Services: How to filter the services to be bound?

I am using Apache Felix and its Declarative Services (SCR) to wire the service dependencies between bundles. For example, if I need access to a java.util.Dictionary I can say the following to have SCR provide one: /** * @scr.reference name=properties interface=java.util.Dictionary */ protected void bindProperties(Dictionary d) { } pr...

Need an example of a primary-key @OneToOne mapping in Hibernate

Can somebody please give me an example of a unidirectional @OneToOne primary-key mapping in Hibernate ? I've tried numerous combinations, and so far the best thing I've gotten is this : @Entity @Table(name = "paper_cheque_stop_metadata") @org.hibernate.annotations.Entity(mutable = false) public class PaperChequeStopMetadata implements S...

How do I override the GenerationType strategy using Hibernate/JPA annotations?

I'm considering using Annotations to define my Hibernate mappings but have run into a problem: I want to use a base entity class to define common fields (including the ID field) but I want different tables to have different ID generation strategies: @MappedSuperclass public abstract class Base implements Serializable { @Id @Col...

Accessing Java annotations from a Taglet

I'm working on a project where we have some custom Taglet classes that are used to modify the Javadocs (such as linking to source code in SVN, adding citations) and so on.One of the things we'd like to do is to be able to get the annotations that are used in the source and manipulate the information from them. It seems that the Taglet ...

Spring question about @ManagedResource annotation for JMX

I would like to find out what the properties of the org.springframework.ManagedResource annotation do as seen in this JavaDoc. I want to understand each param so I can set it to the proper value. If anyone knows where to find more info, I would appreciate it. http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/...

Plugging in to Java compilers

I have a post-compilation step that manipulates the Java bytecode of generated classes. I'd like to make life as painless as possible for library consumers, so I'm looking at ways I can make this process automatic and (if possible) compiler agnostic. The Annotation Processing API provides many of the desired features (automatic service ...

Is there a way to use annotations in Java to replace accessors?

I'm a little new to the Java 5 annotations and I'm curious if either of these are possible: This annotation would generate a simple getter and setter for you. @attribute private String var = ""; The @NotNull annotation indicates that a variable connot be null so you don't have to write that boilerplate code every time. /* * @param ...

hibernate column name issues

@Column(name="DateOfBirth") private Date dateOfBirth; I specifically need the above code to create a column named "DateOfBirth," instead Hibernate gives me a column named date_of_birth. How can I change this? Is there a web.xml property? I came across DefaultNamingStrategy and ImprovedNamingStrategy, but not sure how to specify one ...

Can I generate a compile time error based on the type of the field being Annotated

I have written a java annotation that looks like this: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) // can I further limit this to only fields of type DomainObject? public @interface Owns { } After briefly looking around I couldn't see if there was a way to further limit the usage of this annotation so that only fie...

best (or at least good) guide to Java annotations

There must be a good book/PDF/HTML file that describes the essentials & good practices of annotations in Java. I sort of know what they are from other good Java books, but I'm looking for something that would teach me most of what I would need to know to make good use of them. (preferably in PDF/HTML so I can print it out & read at my le...

creating unit tests (semi-)automatically?

Is there a framework that supports generating some standard unit tests from annotations? An example of what I have in mind would be: @HasPublicDefaultConstructor public class Foo { } This would obviously be used to automatically generate a unit test that checks whether Foo has a default constructor. Am I the only person who thought o...