Hibernate HQL Console : field level annotations and annotatedClasses

Hi,

We have recently upgraded to IDEA7 from IDEA5.1, and I am in the process of getting the HQL Console working in it.

We have our hibernate configuration in our spring applicationContext.xml, all hibernate is annotated, so there's no *.hbm.xml files in the project.

We wrote our own AnnotationSessionFactoryBean so we didnt have to keep adding the hibernate entities to the spring config file every time we created a new one, so our config looks like this...

com.xy.z.database.domain org.hibernate.dialect.OracleDialect false where as traditionally it would have to look like this... com.xy.z.database.domain.MyFirstClass com.xy.z.database.domain.MySecondClass ... com.xy.z.database.domain.MyNthClass org.hibernate.dialect.OracleDialect false ]]>

Now it appears if I use the first config (our preferred way) none of the classes show under the sessionFactory in the Java EE Structure view. If I add the annotatedPackage (which is for package level annotations), then the classes appear but in the HQL Console it says "Query yeilds no results" when I do "from com.xy.z.database.domain.MySecondClass".

So I've been trying with the second config and that appears to work, but I'd prefer not to have to define every single entity in my applicationContext.xml file, as people on the team will forget and it makes the config files look massive (ok i could split it out) Is this the only way to achieve this??

My second problem with the HQL Console is that all our Hibernate Entities are annotated at field level, not method level...

@Entity
public class MyFirstClass {
@Id
@Column(name="ID")
private Long id;

public void setId(Long id) { this.id = id; }
public Long getId() { return id; }
}

and when I run it I get the following....

"from com.xy.z.database.domain.MyFirstClass"

java.lang.NoSuchFieldException: id
at java.lang.Class.getField(Class.java:1520)

1. com.xy.z.database.domain.MyFirstClass@1d17f2df

I've found if change the property to public rather than private (which I obviously don't want to do!) it works, or if I move the annotations to the method level rather than field level it also works. This is a lot of rework as the coding standards at our company say we have to annotate at field level (I also think it makes the file easier to read).

This is a bug in my opinion, even if the database field is annotated at field level it should probably still use the getter or use reflection's setAccessible(true) on the field to read it. Again is there a way around this without spending a few days changing our entities and our coding standards?

Cheers

Andy.

Edited by: kaylanx on Sep 24, 2008 1:14 PM

Please sign in to leave a comment.