annotations

Using Different Hibernate User Types in Different Situations

I am using Hibernate + JPA as my ORM solution. I am using HSQL for unit testing and PostgreSQL as the real database. I want to be able to use Postgres's native UUID type with Hibernate, and use the UUID in its String representation with HSQL for unit testing (since HSQL does not have a UUID type). I am using a persistence XML with dif...

Can I annotate an inherited final property with @Autowire?

Resolution: No I'm no longer extending the original parent. Original: Is there a way to annotate an inherited final setter method? I am extending a class which has a final setter which I would like to @Autowire with Spring. The parent class is from a library and cannot be modified. A workaround I have found is to write a proxy method, ...

how to specify a bean as non lazy with annotations

Does anyone know how to specify a bean as non lazy when using annotations to configure the bean? ...

Hibernate not creating entity tables if embedding components

I have made an application using Java/Hibernate/MySQL, but whenever I try running it, it complains that the table for one of my entity classes has not been created. After some trial and error, I have come to the conclusion that the problem is coming from the way I am mapping embedded components, but I do not know how I may fix it. Here...

Can I put annotations for multiple processors into a Java class?

I'm not really sure how annotations actually work. I'm using JAXB and JPA (with eclipselink) on the same classes, i. e. I get class definitions like this: @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "Channel") @Entity public class Channel extends NamedEntity { @XmlAttribute @XmlSchemaType(name = "anyURI") @Column(n...

Hibernate @OrderBy with referenced class

Hi All, I have a class say: "ClassA" which has a collection of "ClassB" @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "COLUMN_NAME") private List<ClassB> lotsOfClasses; "ClassB" has a mapped class "ClassC" using plain old mapping annotations: public class ClassB { ... @ManyToOne @JoinColumn...

Is there a way to declare an annotation attribute for *any* enum?

At the moment I am developing an annotation-based binding-framework for Java Swing that uses JGoodies Binding under the hood. Unfortunately I am stuck with an annotation for a JRadioButton-binding. What I want to do is specify a property-name of a model which holds a special value (enum). The radio-button shall be selected if this proper...

Strange Java error with annotations

Try to write: List<Object> list; @SuppressWarnings("unchecked") list = (List<Object>) new Object(); It will fail on the 3rd line, on the word list, with the following: list cannot be resolved to a type I understand that it is related to how annotations work. Anybody knows the reasoning behind this? EDIT: thanks for the fast answer....

How to set an expected exception using Scala and JUnit 4

I want to set an expected exception for a JUnit 4 test using Scala. I am current doing something similar to the following: @Test(expected=classOf[NullPointerException]) def someTest() = { // Some test code } But I get the following compiler error: error: wrong number of arguments for constructor Test: ()org.junit.Test ...

Wrap exceptions by runtime exceptions with an annotation

Is there a way to annotate a method so all exceptions thrown are converted to runtime exception automagically? @MagicAnnotation // no throws clause! void foo() { throw new Exception("bar")' } ...

Discover the class of a methodinvocation in the Annotation Processor for java

I am writing some tools for our build system to enforce some strict calling conventions on methods belonging to classes containing certain annotations. I'm using the Compiler Tree API... What i'm wondering is when traversing the 'tree', how can you tell the type of class/interface for a MethodInvocation. I'm subclassing TreePathScan...

When to use @Override in java

Possible Duplicate: When do you use Javas @Override annotation and why? From the javadoc for the @Override annotation: Indicates that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, com...

Spring @Transactional Annotation Best Practice

We are currently discussing the Best Practice for placing the @Transactional annotations in our code. Do you place the @Transactional in the DAO classes and/or their methods or is it better to annotate the Service classed which are calling using the DAO objects? Or does it make sense to annotate both "layers"? ...

Java: Simple technique for annotation-based code injection?

Is there a way to make this code work? LogonControl.java @Audit(AuditType.LOGON) public void login(String username, String password) { // do login } AuditHandler.java public void audit(AuditType auditType) { // persist audit } Endgame being, that each time login() is called, audit() is also called, with the appropriate audittype...

Hibernate CollectionOfElements EAGER fetch duplicates elements

I have a class called SynonymMapping which has a collection of values mapped as a CollectionOfElements @Entity(name = "synonymmapping") public class SynonymMapping { @Id private String keyId; //@CollectionOfElements(fetch = FetchType.EAGER) @CollectionOfElements @JoinTable(name="synonymmappingvalues", joinColumns={@Joi...

Form binding a HashMap using annotation based controller in Spring 2.5

Hello, I have been hitting a brick wall with this problem for some time and no amount of searching and reading has turned up an answer. I have posted on the Spring forums, but to no avail. Maybe someone here can help? I have a bean containing a HashMap which I have bound to form using the Spring:form taglib and Spring:bind. Binding to ...

adding auto-generated date/time stamp to a mapped collection of Strings (hibernate annotations)

Hello, I am using annotations to map a basic collection of Strings to an existing entity like this: Inside the parent entity class: @org.hibernate.annotations.CollectionOfElements @JoinTable (name="GoalToAchieve_entry", joinColumns=@JoinColumn(name="goalToAchieve_id")) @org.hibernate.annotations.Sort(type = org.hibernate.annotations.S...

What are the Pros/Cons of Annotations (non-compiler) compared to xml config files

Hello Everyone When I look at Java frameworks like Hibernate, JPA, or Spring, I usually have the possibility to make my configuration via an xml-file or put annotations directly in my classes. I am cosistently asking myself what way should I go. When I use annotations, I have the class and its configuration together but with an xml I ...

Are java annotation lists supposed to allow an extra comma after the last entry?

I accidentally left an extra comma at the end of one of my annotation lists, but it compiled fine on my machine. For example: @NamedQueries({ @NamedQuery(name="name1",query="FROM Foo"), @NamedQuery(name="name2",query="FROM Bar"), }) Notice the extra comma after the second @NamedQuery. It seems to compile fine on my ...

Can annotations be used for code injection?

Hi all, I realise that this might be a question that has been asked and answered, but please bear with me. I want to know if it is possible to use annotations to inject code into your classes compile time. The classic example is to generate a getter and setter for the members of your object. This is not exactly what I need it for, but ...