• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Insert records on table creation hibernate

 
RamandeepS Singh
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I just want to insert some default records in my table, Like i have user_roles table in hibernate it want to populate it with default records on table creation when i set hbmddl2.auto to true
And i am using hibernate Annotations

Thanks in Advance
Ramandeep S
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can run a bulk insert SQL query during start up.
Are you looking for anything specific?
 
Justin Chi
Greenhorn
Posts: 25
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Add below to your configuration file:
<property name="hibernate.hbm2ddl.auto" value="create"/>

2. Create a file named "import.sql" and put it in class path, add your inserts into "import.sql". Hibernate will load it automaticly.
 
RamandeepS Singh
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Justin Chi wrote:1. Add below to your configuration file:
<property name="hibernate.hbm2ddl.auto" value="create"/>

2. Create a file named "import.sql" and put it in class path, add your inserts into "import.sql". Hibernate will load it automaticly.


Thanks a lot
Justin It works
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic