Sunday, 14 April 2019

Hibernate : How do you map Java Objects with Database tables?


First we need to write Java domain objects (beans with setter and getter).
Write hbm.xml, where we map java class to table and database columns to Java class variables.
Example :

  1. <hibernate-mapping>  
  2.   
  3.   <class name="com.test.User"  table="user">  
  4.   
  5.    <property  column="USER_NAME" length="255"   
  6.   
  7.       name="userName" not-null="true"  type="java.lang.String"/>  
  8.   
  9.    <property  column="USER_PASSWORD" length="255"  
  10.   
  11.      name="userPassword" not-null="true"  type="java.lang.String"/>  
  12.   
  13.  </class>  
  14.   
  15. </hibernate-mapping>  

No comments:

Post a Comment

Spring Boot @ConfigurationProperties and Properties File

 In this tutorial, you will learn to use @ConfigurationProperties to map properties files to POJO classes in Spring Boot application. Let’s ...