-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How to create clone tables using Hibernate
PostPosted: Thu Aug 31, 2017 4:21 am 
Newbie

Joined: Thu Aug 31, 2017 4:17 am
Posts: 1
I have a sample table as follows

Quote:
+ Tbl_template
-id
-name
and POJO in hibernate is class TblTemplate


I want to create some tables that have the same structure as the tbl_template table use the same POJO class TblTemplate

Quote:
-tbl_template_1 (id / name)
-tbl_template_2 (id / name)
...
-tbl_template_3 (id / name)

If I want to create,update,delete data to any table I call that table by table name

If using sql would be easier but I would like to use HQL or hibernate builtin functions

I searched for commands or documents that could do it, but I did not succeed .Please help me!


Top
 Profile  
 
 Post subject: Re: Creating clone table in hibernate java
PostPosted: Thu Aug 31, 2017 4:27 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
TblTemplate can be a @MappedSuperclass while for each specific table you have:

Quote:
- tbl_template_1 (id / name) - mapped to entity TblTemplate1
- tbl_template_2 (id / name) - mapped to entity TblTemplate2
- tbl_template_3 (id / name) - mapped to entity TblTemplate3


So, if the TblTemplate contains the id and name fields, the TblTemplate1 does not need to declare any attribute since they inherit them from TblTemplate.

If you're using PostgreSQL, you can even use table-level inheritance for your design.

Quote:
If I want to create, update, delete data in any table I call that table by table name


You need to use the actual entity type in order to create, update, delete data in a particular table.

Quote:
If using sql would be easier but I would like to use HQL or hibernate builtin functions


You can use HQL as long as you have to make sure you reference the right entity type.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.