Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Relationship b/w app server and Database

 
Mishaal Khan
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying an example to learn JPA .It has 2 Entity beans which has one to one relationship.Database is MySql.
The records are being inserted inside the method of EJB 3(session bean) .The example is working fine and records
are being persisted.The application server is Jboss.

My question is whenever I restart the server the previous inserted records are deleted and an empty table is created.
Also when server is stopped the tables are not listed in Mysql ,and as soon as I start the server it shows tables but empty.

1) Is my assumption right that every time server is started it reads the Entity beans and create tables itself and drop the previous one?

2) what can I do to make the records permanent i.e it is not depndent on server to create or drop the table.

Thanks.



 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mishaal,
I take it you are using Hibernate? Hibernate has a feature called hibernate.hbm2ddl.auto which lets you configure it to create new tables each time. This is useful if you are using Hibernate to generate your schema. Not so much if you want it to stay. Check the value of that setting and turn it off to make your records permanent.
 
Mishaal Khan
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply Jeanne ,your suggestion worked .

One more question as you said you are assuming , I am using Hiberante for schema generation , I am quite new in this area so just wondering in my code i.e Entity beans or Session bean where I am inserting records I am not importing any Hibernate packages or using Session Object to store my data ,I am using EntityManager
for data persistence , so how come I know I am using using Hibernate ?

I just removed these lines from persistence.xml

<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>

</properties>

and it worked , so just inserting or deleting these lines in persistence.xml makes Hibernate enable?


Thanks.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mishaal Khan wrote:One more question as you said you are assuming , I am using Hiberante for schema generation , I am quite new in this area so just wondering in my code i.e Entity beans or Session bean where I am inserting records I am not importing any Hibernate packages or using Session Object to store my data ,I am using EntityManager
for data persistence , so how come I know I am using using Hibernate ?

Hibernate has two forms. One is JPA APIs which include EntityManager. You know you are using Hibernate from the hibernate specific lines in your persistence.xml. I knew you were using Hibernate from the error scenario because I know that is a frequently used feature Hibernate provides.

Mishaal Khan wrote:and it worked , so just inserting or deleting these lines in persistence.xml makes Hibernate enable?Thanks.

Correct. It is just that easy!
 
Mishaal Khan
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So removing those lines from persistence.xml makes Hibernate disable ?

What is the persistence provider then ?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mishaal Khan wrote:So removing those lines from persistence.xml makes Hibernate disable ?

What is the persistence provider then ?

It doesn't disable Hibernate. Just the feature that wipes out your database.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic