0

I have my friend's EJB project that uses hibernate. I am doing my Java project with help of that project. Mine is not an EJB, it is an desktop applicaiton. I have a small hibernate class mapping issue, that is in my friend's project, when I add a new field (say varchar) to database, I can use that field in relevant java class. For example.

In database I add, telephone_no to table A. I can use it like this

class A {
    .......
    private String telephoneNo;

    public String getTelephoneNo(){
          return this.telephoneNo;
    }


    public void setTelephoneNo(String telephoneNo){
          this.telephoneNo = telephoneNo;
    }
    ........
}

but my project, I have to use annotations to set the column name.

The puzzle is, how it resolve the variable name ?. I know in hibernate if the database field and the class variable name is same, then it will automatically maps, if not we should annotations or use xml to map, but in this case (my friend's project) how it automatically resolve ?

Also in my friend's EJB project, I don't see any class mapping at all, when we add table, then it automatically maps to relevant class (I mean after adding class to the EJB).

But how can I achieve this in my Java Desktop application ?

user1479203
  • 437
  • 1
  • 8
  • 16

1 Answers1

0

you ask a lot of question here: 1. you can define to hibernate where to search for entities. you can define to look at the current jar additional jars ... (../MyApp.jar see configuration document) , but classes that used as entities must to be declare either by annotation (@entity) or by xml mapping. 2. for the column name and table name . hibernate follow configuration by exception, so if you dont give a name to a table or field the column name or table name will be the same. you can override the default naming of hibernate (see property name="hibernate.naming_strategy" ).

Avihai Marchiano
  • 3,837
  • 3
  • 38
  • 55
  • thanks for the answer, I read the configuration document but my project is not a EJB, it is a standard desktop application, also I added a class and added @entity annotation, when I run it, I get unknown entity exception, but in EJB project (my friend's) if I add a table to DB, then I can create a class in EJB and use it without writing or editing any EML. – user1479203 Jul 21 '12 at 12:38
  • read this - http://binodsuman.blogspot.co.il/2009/10/jpa-example-outside-container-jpa.html you need that the class will be scanned by hibernate – Avihai Marchiano Jul 21 '12 at 13:39