Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have a helper/convenient method inside a Hibernate entity class? [duplicate]

I have Entity class with a helper method in it. like this..

@Entity
@Table(name = "MEMBER", schema = "APP_SCHEMA")
public class Member {

    private String id;
    private String externalMemberId;

    @Id
    @Column(name = "MEMBER_ID")
    public String getId() {
        return id;
    }

    @Column(name = "EXTERNAL_MEMBER_ID")
    public String getExternalMemberId() {
        return externalMemberId;
    }

    public String getAbc(){
        return "abc";
    }
}

I am getting exception when i start my jboss server while initializing

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: DataDB] Unable to build EntityManagerFactory
Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
Caused by: java.lang.reflect.InvocationTargetException
Caused by: org.hibernate.PropertyNotFoundException: Could not find a setter for property **abc** in class com.myapp.model.Member"}}

Why it is not allowing me to have helper/convenient method inside the entity class? Why it is expecting to map with property? I am using JBoss app server with Hibernate and JPA.

like image 771
sk_rdy Avatar asked Oct 24 '25 19:10

sk_rdy


1 Answers

Hibernate interpretate your getter method getAbc() as getter for abc property that should be persisted. You can use the @Transient annotation to mark the field that it shouldn't be stored in the database. Or try to put the annotations to field insted of getter method.

like image 59
jahra Avatar answered Oct 26 '25 09:10

jahra