简体   繁体   中英

how can we create two independent tables using jpa hibernate

i have two pojo classes and want to store these in two different tables that are not related to each other.

example- here i have two classes A and B and i want to store them in two different tables.u am using postgresql and have a persistence.xml file

@Table(name="A")
class A{

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
int aId;
String aName;
int aAge;

//getters and setters;
}




@Entity
@Table(name="B")
class B{

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
int bId;
String bName;
int bAge;

//getters and setters;
}```

**THERE ARE NO RELATIONSHIP A AND B.. I WANT SEPARATE TABLES FOR BOTH OF THEM.**



  • Set up DB credentials at hibernate
  • At java code, get hibernate session object
  • call save over this object passing the entity to it
  • Tables will be auto created and populated, by Hibernate

Reference Link: https://www.boraji.com/hibernate-5-save-or-persist-an-entity-example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM