3

We have recently upgraded our code base from a 2005 version to the latest version of hibernate.

As a result of that, we're seeing significantly reduced code coverage in a number of our packages. These packages are almost entirely POJOs mapped to hibernate objects, and the difference seems to be in the coverage of getters and setters. Most of these objects are not directly unit tested, so the previous coverage most have come from their usage in some integration test causing hibernate to hit these getters and setters.

Has anyone seen similar things happening? Has there been a change in the way hibernate populates those objects that could explain that?

Most of the fields are set to lazy=false so that's probably out of question.

We are using testng, cobertura and jdk 1.6.

ssedano
  • 8,322
  • 9
  • 60
  • 98
Ashkan Aryan
  • 3,504
  • 4
  • 30
  • 44

2 Answers2

2

I'm not an expert, but maybe the latest version of hibernate inject the values in the fields of your class, while previous version use getters and setters...

Where did you put your annotations?

on fields

@Id private Long id;

or on methods?

@Id public Long getId() { return id; }
Matteo
  • 1,367
  • 7
  • 25
  • Not sure what you mean. But we don't use annotations anyway, using .hbm mapping files. All classes have getter/setters. – Ashkan Aryan Oct 21 '11 at 09:54
  • 1
    Hibernate can use both fields or properties. (I thought you used annotations, and not a mapping file). search for "access" on this page: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html – Matteo Oct 21 '11 at 10:09
1

Has somebody changed something in the xml to change the access to field, e.g.

<property name="xxx" ... access="field"/>

or globally like this?

<hibernate-mapping ... default-access="field">

By default hibernate's access is set to property, so that should use accessors where they are provided.

Goibniu
  • 2,212
  • 3
  • 34
  • 38
  • 1
    That's the route I am investigating, but it appears that it's not the case, there is no reference to default-access in the entire project codebase so it's probably always set to default (which is property as you said) – Ashkan Aryan Oct 21 '11 at 10:29