Illep
Illep

Reputation: 16851

MySQL table in netbeans gets cleared at every time i build the application

I am using netbeans 6.9.1, Glassfish 3.1. I am trying to write some values to the MYSQL table.

this works and the records gets saved to the table with no problem. But everytime when i restart glassfish or build the project all the saved data from the MySQL tables gets erased. How do i avoid this.

I have used Entity beans and Persistence to create table (auto generate tables)

@Entity
public class HotelVacancy implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToOne (cascade=CascadeType.ALL)
private Hotel hotId;
private int noVancies;

public Long getId() {
    return id;
}

 ...

How do i solve this

Upvotes: 0

Views: 289

Answers (3)

Tassos Bassoukos
Tassos Bassoukos

Reputation: 16152

Did your JPA provider create the database tables? If yes, he may still be recreating them every time you application starts. If your model is stable, disable this process.

Upvotes: 0

gred
gred

Reputation: 537

Are you using hibernate??

Do you happen to have a property named hibernate.hbm2ddl.auto in persistence.xml file??

If so, comment out, or remove this property completely from the xml file!

Upvotes: 1

alexblum
alexblum

Reputation: 2238

When you have follow (or similar) row in your persistence.xml:

<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>

delete it.

Upvotes: 2

Related Questions