The problem is you guys are mixing the placement of annotations on both methods and fields. If your @Id is on a method (which I'm guessing it is), Hibernate is in PROPERTY access mode – which means it will ignore annotations on the fields. Of course, you can get around that by explicitly overriding with @Access/@AccessType.
Ex:
FAILS
@Entity
public static class TestEntity {
private long id;
@Transient
private List<TestEntity> foo;
@Id
@GeneratedValue
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public List<TestEntity> getFoo() {
return foo;
}
public void setFoo(List<TestEntity> foo) {
this.foo = foo;
}
}
WORKS
@Entity
public static class TestEntity {
private long id;
private List<TestEntity> foo;
@Id
@GeneratedValue
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Transient
public List<TestEntity> getFoo() {
return foo;
}
public void setFoo(List<TestEntity> foo) {
this.foo = foo;
}
}
WORKS
@Entity
public static class TestEntity {
@Id
@GeneratedValue
private long id;
@Transient
private List<TestEntity> foo;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public List<TestEntity> getFoo() {
return foo;
}
public void setFoo(List<TestEntity> foo) {
this.foo = foo;
}
}
|