Hibernate with JPA ignoring @Formula?

You're trying to map the state twice : once by adding annotations to the field, and once by adding annotations to the getter. Put all the annotations at the same place (and at the same place as the Id annotation).

You're trying to map the state twice : once by adding annotations to the field, and once by adding annotations to the getter. Put all the annotations at the same place (and at the same place as the @Id annotation). But this is really confusing.

Your state is transient (meaning it's not mapped at all, and should not be read from the database), but it's also enumerated (why would bernate use this annotation since it's supposed to be transient), and a formula. Finally, a formula is some piece of SQL that's added in every SQL that is used to load your entity. So it should not contain a select clause, or a from clause, but just a formula using some of the columns of the table itself.

For example, suppose you have a table with a column salary and a column bonus, you could have a formula for a field totalIncome which would be 'bonus + salary'. But id doesn't go much further than that.

– Udo Fholl Oct 20 at 8:23 No. Formula already says : this is not a column in DB, but a value that is computed from other ones.So Transient is not needed. – JB Nizet Oct 20 at 8:34 Then why does it fails to load the persistence unit due to that column being missing?

– Udo Fholl Oct 20 at 9:03 Maybe I'm wrong then, but all the examples of Formula in the bernate documentation don't use the Transient annotation. And usually, bernate doesn't care about a missing column in the database until it tries loading or persisting somthing to the table. – JB Nizet Oct 20 at 14:25 Well, are they using JPA in their examples, I read all through the documentation and could not find a complete example using JPA.

The thing is it keeps failing if the column is not there. Maybe is failing the JPA? +1 for your wise advises and clarification anyway – Udo Fholl 03 May8 at 8:33.

I think this should work. I think @Transient is making bernate ignore the attribute at all. @Entity @Table(name = "MyEntity") @org.hibernate.annotations.

Table(appliesTo = "MyEntity") public class MyEntity { // MAYBE YOU HAVE TO MOVE IT TO THE GETTER @Enumerated(value = javax.persistence.EnumType. STRING) // REMOVE THIS @Transient private State state; @Enumerated(value = javax.persistence.EnumType. STRING) // MOVED @Formula(value = "select e.

State from OtheEntity e") public State getState() { return this. State; } //setter and another properties }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions